#include <bits/stdc++.h>
using namespace std;

#define int long long
#define p " "
#define e endl
#define vec vector<int>

void log_int(string S = "", vec v = {})
{
    if (S != "")
    {
        cout << S << p;
    }
    for (auto &&el : v)
    {
        cout << el << p;
    }
    cout << e;
}

void Print_vec(vec v)
{
    for (auto &&el : v)
    {
        cout << el << p;
    }
    cout << e;
}


void task()
{
    int n;
vector<int> boys_q;
vector<pair<int, int>> matching;
vector<pair<int, set<int>>> girls_funs;
map<pair<int, int>, int> add_search; // pair - target, int - place for adding balls;



    cin >> n;    
    boys_q.resize(n + 5);
    matching.resize(n + 5);
    girls_funs.resize(2 * n + 10, {0, set<int>()});

    int a, b, c;
    for (int i = 0; i < n;){
        i++;
        cin >> a >> b >> c;
        girls_funs[a].first += c;
        girls_funs[a].second.insert(i);
        girls_funs[b].first += c;
        girls_funs[b].second.insert(i);
        boys_q[i] = c;
        matching[i] = {a, b};
    }

    int ans = 0;
    for (int i = 1; i <= 2*n+1; i++){
        if (girls_funs[i].first > girls_funs[ans].first){
            ans = i;
        }
    }

    

    cout << girls_funs[ans].first<<e;
}

signed main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 0; i < n;i++){
            //cout << e << e << i << e;
        task();
    }
}