#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define all(a) (a).begin(), (a).end()

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

    int tc;
    cin >> tc;
    while (tc--) {
        int n;
        cin >> n;
        vector<vector<pair<int, ll>>> g(2 * n);
        map<int, ll> c;
        for (int i = 0; i < n; i++) {
            int x, y, z;
            cin >> x >> y >> z;
            x--, y--;
            g[x].push_back({y, z});
            g[y].push_back({x, z});
            c[x] += z; c[y] += z;
        }
        ll res = 1;
        for (auto [_, x] : c) res = max(res, x);
        vector<bool> visited(2 * n);
        function<void (int, pair<int, ll>, pair<int, ll>)> dfs = [&](int i, pair<int, ll> p, pair<int, ll> p2) {
            visited[i] = 1;
            for (auto [j, x] : g[i]) {
                if (j == p2.first) res = max(res, x + p.second + p2.second);
                if (!visited[j]) dfs(j, {i, x}, p);
            }
        };
        dfs(0, {-1, -1}, {-1, -1});
        cout << res << '\n';
    }
}