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

using ll= long long;

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

    ll t;
    cin>>t;
    for (ll i = 0;i< t;i++) {
        ll n;
        cin>>n;
        vector<vector<ll>> boys_types(n, vector<ll>(3,0));
        vector<ll> sums(2*n+1, 0);
        for (ll j = 0;j < n;j++) {
            for (ll u = 0; u < 3; u++) {
                cin>> boys_types[j][u];

            }
            sums[boys_types[j][0]]+=boys_types[j][2];
            sums[boys_types[j][1]]+=boys_types[j][2];
        }
        ll ans =0;
        for (ll j = 0; j < 2*n+1;j++) {
            ans = max(ans, sums[j]);
        }
        cout << ans << endl;
    }
    return 0;
}
