#include <bits/stdc++.h>
#define int long long


using namespace std;

vector<int> sz;
vector<int> lnk;


void solve(){
    int n; cin >> n;
    sz.resize(2*n+1);
    lnk.resize(2*n+1);

    for(int i = 0; i < 2*n+1; i++){
        sz[i] = 0;
        lnk[i] = i;
    }

    int a, b, c;
    map<int, int> cc;
    for(int i = 0; i < n; i++){
        cin >> a >> b >> c;
        sz[a] += c;
        sz[b] += c;
    }
    int mx = sz[0];
    for(auto x: sz){
        mx = max(mx, x);
    }
    cout << mx << endl;
}

signed main()
{
    int t = 1; cin >> t;
    while(t--) solve();
    return 0;
}
