#include <bits/stdc++.h>

#define ll long long

using namespace std;


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll C;
    cin >> C;
    while(C--){
        ll n;
        cin >> n;
        ll ans = 0;
        vector<ll> anfan(2 * n + 1, 0);
        for(ll i = 0; i < n; i++){
            ll a, b, c;
            cin >> a >> b >> c;
            anfan[a] += c;
            anfan[b] += c;
            ans = max(ans, anfan[a]);
            ans = max(ans, anfan[b]);
        }
        
        cout << ans << endl;
    }

}

