#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll SIZ = ((ll)1e5 + 5), LONGBOI = ((ll)1e12 + 5);
mt19937_64 REALrandom(chrono::system_clock::to_time_t(chrono::system_clock::now()));

struct mycompare{
    bool operator()(ll a, ll b) const{
        return a%10 > b%10;
    }
};

struct str{
    ll n;
};

bool operator < (str a, str b){
    return a.n < b.n;
}

ll n, a, b, c;
ll num[SIZ];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll T;
    cin>>T;
    while(T>0){
        T--;
        cin>>n;
        for(int i=1;i<=2*n;i++) num[i]=0;
        for(int i=1;i<=n;i++){
            cin>>a>>b>>c;
            num[a]+=c;
            num[b]+=c;
        }
        ll ans=LONGBOI, mx=-LONGBOI;
        for(int i=1;i<=2*n;i++){
            if(num[i]>mx){
                mx=num[i];
                ans=i;
            }
        }
        cout<<mx<<endl;
    }
    return 0;
}
