#include <bits/stdc++.h>
#include <random>

using namespace std;

#define ll long long
#define endl '\n'
#define ld long double
#define pb push_back

const ll clasik = 7e5+7;
const ll INF = 1e17;
const ll mod = 1e9+7;

ll df[clasik];

ll cntv[2*clasik];

mt19937 vira(228);

vector <ll> per[2*clasik];
set <ll> rev[2*clasik];

ll cherez[2*clasik];

void solve() {

    ll n;

    cin >> n;

    ll a , b , c;
    map<pair<ll,ll> , ll > cnt;
    for (int i= 1 ; i<=n ; i++) {
        cin>>a>>b>>c;
        cnt[{a , b}]+=c;
        cntv[a]+=c;
        cntv[b]+=c;
    }

    ll res = 0;

    for (int i = 1 ; i<=2*n ; i++) {
        res = max(res , cntv[i]);
        //cout<<cntv[i]<<endl;
        for (int j = i+1 ; j<=2*n ; j++) {
            for (int k = j+1 ; k<=2*n ; k++) {
                if (cnt[{i,j}]==0 || cnt[{i,k}]==0 || cnt[{j,k}]==0) continue;
                ll curr = cnt[{i , j}] + cnt[{j , k}] + cnt[{i , k}];
                res = max(curr , res);
            }
        }
    }

    cout<<res<<endl;

    for (int i =1 ;i<=2*n ; i++) cntv[i] = 0;

}

signed main() {
    
    int t = 1;

    cin>>t;

    while(t--) solve();

    return 0;
}