#include <bits/stdc++.h>
#define int long long
#define elif else if
#define pb push_back
#define vt vector

using namespace std;

vt<int> sz;
vt<int> link;

int fnd(int x){
    while(link[x] != x){
        x = link[x];
    }
    return x;
}

void unite(int a, int b){
    if(sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    link[b] = link[a];
}

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

    for(int i = 0; i < 2*n+1; i++){
        sz[i] = 0;
        link[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;
}
