/*IN FISH AT EGOI I TRUST*/
/*IN FISH AT EGOI I TRUST*/
/*IN FISH AT EGOI I TRUST*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
/*#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt")*/
ll mod,tt,a[1000009],v1,v2,pr[1000009],d,n,g[2000009];
vector<ll> A[1000009];
map<pll,ll> mp;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    mod=1e9+7;
    cin>>tt;
    while(tt--){
        cin>>n;
        for(int i=1;i<=2*n;i++) g[i]=0;
        mp.clear();
        for(int i=1;i<=n;i++) {
            cin>>v1>>v2>>d;
            g[v1]+=d;
            g[v2]+=d;
            if(v1>v2) swap(v1,v2);
            mp[{v1,v2}]+=d;
        }
        ll res=0;
        for(int a=1;a<=2*n;a++) for(int b=a+1;b<=2*n;b++) for(int c=b+1;c<=2*n;c++) {
            res=max(res,mp[{a,b}]+mp[{b,c}]+mp[{a,c}]);
        }
        for(int i=1;i<=2*n;i++) res=max(res,g[i]);
        cout<<res<<"\n";

    }





    return 0;
}
