#include <bits/stdc++.h>
#include <random>

using namespace std;

#define ll long long
#define endl '\n'
#define ld long double
#define pb push_back

const ll clasik = 7e5+7;
const ll INF = 1e17;
const ll mod = 1e9+7;

ll df[clasik];

ll cnt[2*clasik];

mt19937 vira(228);

vector <ll> per[2*clasik];



void solve() {

    ll n;

    cin >> n;

    ll a , b ,c;

    map< pair<int,int> , ll > used; 

    for (int i = 1 ; i<=n ; i++) {
        cin>>a>>b>>c;
        cnt[a] += c;
        per[a].pb(b);
        used[{a,b}] = c;
    }
    
    ll res = 0;
    for (int i = 2*n ; i>=1 ; i--) {
        res = max(res , cnt[i]);
    }

    cout<<res<<endl;

    for(int i= 1 ; i<=2*n ; i++) {
        cnt[i] = 0;
    }

}

signed main() {
    
    int t = 1;

    cin>>t;

    while(t--) solve();

    return 0;
}