#include <bits/stdc++.h>
using namespace std;
int m = 7 * 1e5;
int main() {
    int t;
    cin >> t;

    int n=0,a[m],b[m],c[m],res=0,am[2*m];
    for(int T = 0; T < t; T++)
    {
        cin >> n;
        res = 0;
        for(int i = 0; i < n; i++)
        {
            cin >> a[i] >> b[i] >> c[i];
            am[a[i]] += c[i];
            am[b[i]] += c[i];
        }

        for(int i = 0; i < 2*m; i++)
        {
            if(am[i] > res)
            {
                res = am[i];
            }
            am[i] = 0;
        }

        cout << res << "\n";
    }
}