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

void solve() {
    int n;
    cin>>n;
    vector<ll> a(n), b(n), c(n);
    vector<map<ll, ll>> grp(2 * n);
    for (int i = 0; i < n;i++) {
        cin>>a[i]>>b[i]>>c[i]; a[i]--; b[i]--;
        grp[a[i]][b[i]] += c[i];
        grp[b[i]][a[i]] += c[i];
    }
    ll res = 0;
    for (auto& arr : grp) {
        ll cr = 0;
        for (auto& [k, v] : arr) {
            cr += v;
        }
        res = max(res, cr);
        for (int i = 0; i < n;i++) {
            if (arr.find(a[i]) != arr.end() && arr.find(b[i]) != arr.end()) {
                res = max(res, arr[a[i]] + arr[b[i]] + c[i]);
            }
        }
    }
    cout << res << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin>>t;
    while (t) {
        solve();
        t--;
    }
}
