#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;
        map<int, ll> c;
        for (int i = 0; i < n; i++) {
            int x, y, z;
            cin >> x >> y >> z;
            c[x] += z; c[y] += z;
        }
        ll res = 1;
        for (auto [_, x] : c) res = max(res, x);
        cout << res << '\n';
    }
}