#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
typedef long long ll;

int t;

void solve(){
    int n;
    cin>>n;
    vector<ll> a(n), b(n), c(n);
    unordered_map <ll, ll> g;
    ll ans = 0;

    for(int i=0; i<n; i++){
        cin>>a[i]>>b[i]>>c[i];
        g[a[i]]+=c[i];
        g[b[i]]+=c[i];
        ans = max(ans, max(g[a[i]], g[b[i]]));
    }

    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}