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

typedef long long ll;

ll n, ans;

void go()
{
    ans = 0;
    cin>>n;
    vector<vector<ll>> e(2 * n + 1);
    map<pair<ll, ll>, ll> m;
    for(ll i = 1;i <= n; i++) 
    {
        ll v, w, c;
        cin>>v>>w>>c;
        if(w < v) swap(v, w);
        e[v].push_back(w);
        e[w].push_back(v);
        m[{v, w}] += c;
    }

    for(ll i = 1; i <= n * 2; i++)
    {
        ll sum = 0;
        vector<ll> delta(1, i);

        for(ll x : e[i])delta.push_back(x);
        sort(delta.begin(), delta.end());

        for(ll j = 0; j < delta.size() - 1; j++) for(ll g = j+  1; g < delta.size(); g++) sum += m[{delta[j], delta[g]}];
        ans = max(sum, ans);
    }
    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();
}
