#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=14*(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){

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

        for(auto y: a[to]){
            for(auto z: a[y.first]){
                if(z.first==v){
                    ans=max(ans, x.second+y.second+z.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;
        vector<ll> all;
        for(int i=1; i<=n; i++){
            cin>>x>>y>>cnt;
            a[x].push_back({y, cnt});
            a[y].push_back({x, cnt});
            all.push_back(x); all.push_back(y);
            mp[x]+=cnt;
            mp[y]+=cnt;
            vis[i]=0;

        }
        ll mx=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++){
            dfs(i);
        }
        for(auto el: all){
            a[el].clear();
        }
        mp.clear();


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

    return 0;
}
