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

void solve() {
    int n;
    cin >> n;
    vector <array <long long, 3> > v(n);

    map <long long, long long> m;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i][0] >> v[i][1] >> v[i][2];

        m[v[i][0]] += v[i][2];
        m[v[i][1]] += v[i][2];

        ans = max(ans, m[v[i][0]]);
        ans = max(ans, m[v[i][1]]);
    }
    cout << ans << "\n";
}

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

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