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

struct st{
    int a,b,c;
};

int main()
{
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        map<int,st> mas;
        vector<int> mas1[1400005];
        for(int i=1;i<=n;i++)
        {
            int a,b,c;
            cin>>a>>b>>c;
            st el;
            el.a=a;
            el.b=b;
            el.c=c;
            mas[i]=el;
            mas1[a].push_back(i);
            mas1[b].push_back(i);
        }
        int res=0;
        for(int i=1;i<=n*2;i++)
        {
            int el=0;
            for(auto j:mas1[i])
            {
                el+=mas[j].c;
            }
            res=max(res,el);
        }
        cout<<res<<endl;

    }
}
