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

typedef long long ll;

ll n, ans, delta[70001];

void go()
{
    ans = 0;

    cin>>n;
    for(ll i = 1; i <= n * 2; i++) delta[i] = 0;
    map<pair<ll, ll>, ll> e;
    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;
        e[{w, v}] += c;
        delta[v] += c;
        delta[w] += c;
        ans = max(ans, max(delta[v], delta[w]));
        for(ll j = 1; j <= n * 2; j++) if(j != v && j != w && e[{j, v}] && e[{j, w}]) ans = max(ans, e[{v, w}] + e[{j, v}] + e[{j, w}]);
    }

    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();
}