#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        pair<pair<int,int>,int>a[n];
        int mx = 0;
        map<int,int>mp;
        for(int i = 0;i<n;i++){
            cin>>a[i].first.first>>a[i].first.second>>a[i].second;
            mx = max(mx,a[i].second);
            mp[a[i].first.first]+=a[i].second;
            mp[a[i].first.second]+=a[i].second;
            mx = max(mx,max(mp[a[i].first.first],mp[a[i].first.second]));
        }
        cout<<mx<<endl;
    }
}
