#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll DIM = 2*7e5+7;
vector<ll> Q[DIM];
ll a[DIM], b[DIM], c[DIM], d[DIM];
map<ll, ll> m[DIM];
void solve(){
    ll n;
    cin >> n;
    for(int i=1; i<=2*n; i++){
        d[i] = 0;
        m[i].clear();
    }

    for(int i=1; i<=n; i++){
        cin >> a[i] >> b[i] >> c[i];

        d[a[i]] += c[i];
        d[b[i]] += c[i];
    }

    ll ans = 0;
    for(int i=1; i<=2*n; i++){
        ans = max(ans, d[i]);
        
    }
    cout << ans << endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
