#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>

using namespace std;
using ll = long long;

void handle_test() {
    int n;
    cin >> n;

    vector<map<int, ll>> edges(n * 2, map<int, ll>{});

    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        a -= 1;
        b -= 1;

        edges[a][b] = c;
        edges[b][a] = c;
    }

    vector<int> order(n * 2, -1);
    vector<int> parents(n * 2, -1);
    vector<int> parent_c(n * 2, -1);

    ll res = 0;

    for (int i = 0; i < n * 2; i++) {
        for (auto [j, c_j] : edges[i]) {
            for (auto [k, c_k] : edges[j]) {
                if (k == i) {
                    continue;
                }

                if (edges[k].find(i) != edges[k].end()) {
                    res = max(res, c_j + c_k + edges[k][i]);
                }
            }
        }
    }

    for (int i = 0; i < n * 2; i++) {
        ll sum = 0;

        for (auto [_, c] : edges[i]) {
            sum += c;
        }

        res = max(res, sum);
    }

    cout << res << "\n";
}

int main() {
#ifndef DEBUG
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    int tests;
    cin >> tests;

    while (tests--) {
        handle_test();
    }

    return 0;
}
