#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>


using namespace std;
#define ll long long
#define endl '\n'
#define itn int

const long long oo=1000000000000;
const long long N=1500005;

vector<vector<pair<ll,ll>>>g(N);
vector<bool>used(N);
ll mx=0;
void cycle(ll v,ll pred,ll d)
{
   // cout<<v<<" "<<d<<endl;;

    if(used[v]==true)
    {
        mx=max(mx,d);
       //  cout<<mx<<endl;
        return;

    }
    used[v]=true;
    for(auto [val,to]: g[v])
    {
        if(to==pred)
        {
            mx=max(mx, val);
          //  cout<<" f "<<mx<<endl;
           // break;
        }
        else
        {

            cycle(to,v,d+val);
        }

    }

}

int main()
{

//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
//    cout.tie(0);


    ll test;
    cin>>test;
    while(test--)
    {

        ll n;
        cin>>n;
        vector<ll>m(2*n+1,0);
        for(int i=1; i<=2*n; i++)
        {

            g[i].clear();

        }
        used.clear();
        used.resize(2*n+1,false);
        ll a[n+1],b[n+1],c;
        for(itn i=0; i<n; i++)
        {

            cin>>a[i]>>b[i]>>c;
            m[a[i]]+=c;
            m[b[i]]+=c;
            g[a[i]].push_back({c,b[i]});
            g[b[i]].push_back({c,a[i]});
        }
        mx=0;
        for(itn i=1; i<=2*n; i++)
        {
            mx=max(mx,m[i]);
//            cout<<"asw";

            if(used[i]==false) cycle(i,i,0);
        }
        cout<<mx<<endl;
        //<<"xas ";

    }

}
