#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll t, n, a, b, c;
    cin >> t;
    map<ll, ll> mp;

    while (t--) {
        cin >> n;
        ll A[2*n+1][2*n+1];
        for (int i=1; i<2*n+1; i++) {
            for (int j=1; j<2*n+1; j++) {
                A[i][j] = 0;
            }
        }
        mp.clear();

        for (int i=0; i<n; i++) {
            cin >> a >> b >> c;
            A[a][b] = c;
            A[b][a] = c;
            //cout << A[a][b] << " " << A[b][a] << " " << c << "\n";
            mp[a]+=c;
            mp[b]+=c;
        }
        ll mx = -1;
        for (auto u: mp)
            mx = max(mx, u.ss);
        for (int i=1; i<2*n+1; i++) {
            for (int j=1; j<2*n+1; j++) {
                for (int k=1; k<2*n+1; k++) {
                    if (A[i][j] != 0 && A[i][k] != 0 && A[j][k] != 0) {
                        mx = max(mx, (A[i][j]+A[i][k]+A[j][k]));
                        //cout << i << " " << j << " " << k << "\n";// << " " << A[i][j] << " " << A[i][k] << " " << A[j][k] << "\n";
                    }
                }
            }
        }
        cout << mx << "\n";
    }
}