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

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define fastread ios_base::sync_with_stdio(0);cin.tie(NULL)
#define sum(x) accumulate(all(x),0LL)
#define what_is(x) cerr << #x << " = " << (x) << '\n'

struct A {
    int a,b,c;
};

int main()
{
    fastread;
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<A> v(n);
        ll mx = 0;
        map<int,int> mp;
        for (int i=0;i<n;++i) {
            cin >> v[i].a >> v[i].b >> v[i].c;
            mp[v[i].a] += v[i].c;
            mp[v[i].b] += v[i].c;
            mx = max(mp[v[i].b],mp[v[i].a]);
        }
        cout << mx << '\n';
    }

    return 0;
}

