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

typedef long long ll;

ll n, ans, delta[1400001];

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;
        delta[v] += c;
        delta[w] += c;
        ans = max(ans, max(delta[v], delta[w]));
    }

    for(ll i = 1; i <= n * 2; i++)
    {
        for(auto j : e)
        {
            ll x = j.first.first, y = j.first.second;
            if(j.second && e[{min(i, x), max(i, x)}] && e[{min(i, y), max(i, y)}]) ans = max(ans, j.second + e[{min(i, x), max(i, x)}] +e[{min(i, y), max(i, y)}]);
        }
    }

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