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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int T;
    cin >> T;
    while(T--){
        ll n;
        cin >> n;
        ll a[n], b[n], c[n];
        for (int i=0; i<n; i++){
            cin >> a[i] >> b[i] >> c[i];
        }
        vector<ll> arr(2*n+1,0);
        for (int i=0; i<n; i++){
            arr[a[i]]++;
            arr[b[i]]++;
        }
        vector<ll> sum(2*n+1,0);
        for(int i=0; i<n; i++){
            sum[a[i]]+=c[i];
            sum[b[i]]+=c[i];
        }
        ll sum1 = *max_element(sum.begin(), sum.end());
        cout << sum1 << endl;
    }
}