#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back

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

    ll t, n, a, b, c;
    cin >> t;
    map<ll, ll> mp;

    while (t--) {
        cin >> n;
        mp.clear();

        for (int i=0; i<n; i++) {
            cin >> a >> b >> c;
            //cout << A[a][b] << " " << A[b][a] << " " << c << "\n";
            mp[a]+=c;
            mp[b]+=c;
        }
        ll mx = -1;
        for (auto u: mp)
            mx = max(mx, u.ss);
        
        cout << mx << "\n";
    }
}