#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;
    unordered_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();

        ll mx = -1;
        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;
            mx = max(mx, max(mp[a], mp[b]));
        }
        for (int i=1; i<2*n+1; i++) {
            for (int j=i+1; j<2*n+1; j++) {
                for (int k=j+1; k<2*n+1; k++) {
                    mx = max(mx, (A[i][j]+A[i][k]+A[j][k]));
                }
            }
        }
        cout << mx << "\n";
    }
}