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

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

    int t;
    cin>>t;

    for(int indx = 0;indx<t;indx++){
        int n,res;
        cin>>n;
        vector<int>a(n);
        vector<int>b(n);
        vector<int>c(n);
        vector<int>sm(2*n+1,0);
        for(int i = 0; i < n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            sm[a] += c;
            sm[b] += c;
        }
        int max = 0;
        for(int i = 0;i<=n*2;i++){
            if(sm[i]>max){
                max = sm[i];
            }
        }
        cout << max <<endl;
    }
    
}
