#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll n, ans, delta[1400001];
map<pair<ll, ll>, ll> e;

void go()
{
    ans = 0;
    e.clear();

    cin>>n;
    for(ll i = 1; i <= n * 2; i++) delta[i] = 0;
    for(ll i = 1;i <= n; i++) 
    {
        ll v, w, c;
        cin>>v>>w>>c;
        if(v > w) swap(v, w);
        e[{v, w}] += c;
        delta[v] += c;
        delta[w] += c;
        ans = max(ans, max(delta[v], delta[w]));
    }

    for(ll i = 1; i<= n * 2 - 2; i++) for(ll j = i+ 1; j<= n * 2 - 1; j++) for(ll g = j + 1; g<= n * 2; g++) if(e[{i, j}] && e[{i, g}] && e[{j, g}]) ans = max(ans, e[{i, j}] + e[{i, g}] + e[{j, g}]);

    cout<<ans<<'\n';
    return;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int test_cnt = 1;
    cin>>test_cnt;
    while(test_cnt--) go();
}