#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct DSU {
    int n;
    vector<int> p, h;

    DSU(int m) {
        n = m;
        p.assign(n + 1, -1);
        h.assign(n + 1, 1);

        for (int i = 0; i <= n; i++) {
            p[i] = i;
            h[i] = 1;
        }
    }

    int findParent(int node) {
        if (p[node] == node) {
            return node;
        }
        return p[node] = findParent(p[node]);
    }
};

struct edg {
    ll a, b, c;
};

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

    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;

        n *= 2;

        vector<pair<int, ll>> adj[n + 1];
        map<pair<int, int>, ll> edge;
        edg edges[n / 2];

        for (int i = 0; i < n / 2; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            adj[a].push_back({b, c});
            adj[b].push_back({a, c});
            edge[{a, b}] = c;
            edge[{b, a}] = c;
            edges[i] = {a, b, c};
        }

        // one node

        ll ans = 0;
        for (int i = 1; i <= n; i++) {
            ll here = 0;
            for (auto ad : adj[i]) {
                here += ad.second;
            }
            ans = max(ans, here);
        }

        // loop
        
        for (auto ed : edges) {
            int node = ed.a, other = ed.b;
            if (adj[ed.b] < adj[ed.a]) {
                node = ed.b;
                other = ed.a;
            }


            for (auto ad : adj[node]) {
                if (edge.count({ad.first, other})) {
                    if (ed.c + ad.second + edge[{ad.first, other}] > ans) {
                        ans = ed.c + ad.second + edge[{ad.first, other}];
                    }
                }
            }
        }

        printf("%lld\n", ans);
    }

    
}