#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 t;
    cin >>t;
    while (t--)
    {
        ll n;
        cin >>n;
        map<ll,ll> mp;
        ll res = 0;
        for (int i=0;i<n;i++)
        {
            ll x,y,z;
            cin >>x>>y>>z;
            mp[x] += z;
            mp[y] += z;
            res = max(res,mp[x]);
            res = max(res,mp[y]);
        }
        cout <<res<<endl;
    }
}
