#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t;
    cin >> t;
    while (t--) {
        ll n;
        cin >> n;
        vector<ll> a(n), b(n), c(n);
        vector<ll> popularity(2*n + 1, 0);
        ll max = 0;
        for (ll i = 0; i < n; i++) {
            cin >> a[i] >> b[i] >> c[i];
            popularity[a[i]] += c[i];
            popularity[b[i]] += c[i];
        }
        for (ll i = 0; i < n; i++) {
            if (popularity[i] > max) {
                max = popularity[i];
            }
        }
        cout << max << '\n';
    }
}