#include <bits/stdc++.h>
//#define endl '\h'
#define se second
#define fi first




typedef long long ll;
//typedef pair<ll,ll> pll;






using namespace std;




ll n,m,res;
map<long long, long long> mpp;
set<ll> s;
void solve(){
    ll a,b,c;
    mpp.clear();
    s.clear();
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a >> b >> c;
        mpp[a]+=c;
        mpp[b]+=c;
        s.insert(a);
        s.insert(b);
    }
    res=0;
    for(auto tm:s){
        res=max(mpp[tm],res);
    }
    cout << res << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
