#include<bits/stdc++.h>
/*#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,tune=native")*/
#define ll long long
#define fr first
#define sc second
#define pb push_back
using namespace std;
unordered_map<ll, ll>mp;
int main()
{
    /*ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        for(ll i=0;i<n;i++){
            ll a, b, c;
            cin>>a>>b>>c;
            mp[a]+=c;
            mp[b]+=c;
        }
        ll mx=0;
        for(auto it=mp.begin();it!=mp.end();it++)mx=max(mx, it->sc);
        cout<<mx<<endl;
        mp.clear();
    }
}
