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

typedef long long ll;

struct bys
{
    ll a, b, c;
};

ll n, ans;
bys ar[700001];

void go()
{
    ans = 0;

    cin>>n;
    map<ll, ll> m;
    for(ll i = 1;i <= n; i++) 
    {
        cin>>ar[i].a>>ar[i].b>>ar[i].c;
        m[ar[i].a] += ar[i].c;
        ans = max(ans, m[ar[i].a]);
        m[ar[i].b] += ar[i].c;
        ans = max(ans, m[ar[i].b]);
    }

    cout<<ans<<'\n';
    return;
}

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

    int test_cnt = 1;
    cin>>test_cnt;
    while(test_cnt--) go();
}
