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

void solve ()
{
    int n;
    cin >> n;
    map <int, int> mp;
    int res = 0;

    for (int i = 1; i <= n; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        mp[a]+=c;
        mp[b]+=c;

        res = max ({res, mp[a], mp[b]});
    }

    cout << res << endl;
}

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

    int t;
    cin >> t;

    while (t--)
    {
        solve();
    }
}
