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

#define int long long

const int mxN = 7e5;
int t, n, a[mxN], b[mxN], c[mxN];

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

        cin >> t;
        while(t--) {
                cin >> n;
                vector<int> sz(2 * n + 1, 0);
                vector<vector<int>> v(2 * n + 1);
                for(int i = 0; i < n; ++i) {
                        cin >> a[i] >> b[i] >> c[i];
                        sz[a[i]] += c[i];
                        sz[b[i]] += c[i];
                        v[a[i]][b[i]] += c[i];
                        v[b[i]][a[i]] += c[i];
                }
                int mx = 0;
                for(int i = 1; i <= 2 * n; ++i) {
                        mx = max(mx, sz[i]);
                }       
                for(int i = 0; i < n; ++i) {
                        for(int z = 1; z <= 2 * n; ++z) {
                                if(z != a[i] && z != b[i]) {
                                    mx = max(mx, v[z][a[i]] + v[z][b[i]] + c[i]);
                                }
                        }
                }
                cout << mx << endl;
        }
}



