#include <iostream>
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define endl "\n"
//#define vector<ll> vll;
//#define fi first;
//#define se second;
//#define pb push_back;
typedef pair<ll, ll> pll;
const ll dim=7*(1e5+6);
ll n, t;
string s;
vector<pll> a[dim];
ll vis[dim];
ll ans=0;
ll cur=0;
ll cur1=0;
ll cur2=0;
void dfs(ll v, ll p, ll gp, ll cur1, ll cur2){
    if(vis[v])return ;
    vis[v]=1;

    for(auto x: a[v]){
        ll to=x.first;

        if(to==p)continue;
        if(to==gp){
            ans=max(ans, cur1+cur2+x.second);

        }
        dfs(x.first, v, p, cur2, x.second);
    }

}

int main()
{
    ll x, y, cnt;
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   cin>>t;
   //t=1;
    while(t--){
        cin>>n;
        ans=0;
        map<ll, ll> mp;
        for(int i=1; i<=n; i++){
            cin>>x>>y>>cnt;
            a[x].push_back({y, cnt});
            a[y].push_back({x, cnt});
            mp[x]+=cnt;
            mp[y]+=cnt;
            vis[i]=0;

        }
        ll mx=0;
        dfs(1, 0, 0, 0, 0);
        for(auto x:mp){
           // cout<<x.first<<" "<<x.second<<endl;
            if(mx<x.second){
                mx=x.second;
            }
        }
        for(int i=1; i<=2*n; i++){
            a[i].clear();
        }
        mp.clear();


        cout<<max(mx, ans)<<endl;
    }

    return 0;
}
