#include <iostream>
#include <vector>
using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    vector<int> ans (t);
    for (int t0 = 0; t0 < t; t0++)  {
        long long n, a, b, c;
        cin >> n;
        int max = 0;
        vector<int> arr (1e6, 0);
        for (int i = 0; i < n; i++) {
            cin >> a >> b >> c;
            arr[a] += c;
            arr[b] += c;
            if (arr[b] > max) {
                max = arr[b];
            }
            if (arr[a] > max) {
                max = arr[a];
            }
        }
        ans[t0] = max;
    }
    for (int i : ans)
        cout << i << "\n";
    return 0;
}
