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

#define int long long
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fst first
#define snd second
#define ff first
#define st second
#define endl "\n"
#define len(x) x.size()

void I_LOVE_PEREKOPSKA() {
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    map<int, int> cnt;
    for (int i=0;i<n;i++) {
        cin>>a[i]>>b[i]>>c[i];
        cnt[a[i]]+=c[i];
        cnt[b[i]]+=c[i];
    }
    vector<pair<int, int>> h;
    for (int i=0;i<n;i++)
        for (int j=0;j<c[i];j++)
            h.push_back({a[i],b[i]});
    sort(all(h));
    // for (auto [k, m]:h)
    //     cout<<k<<" "<<m<<endl;
    int tp_c = 0;
    int mx = 0;
    for (auto x:cnt) {
        // cout<<"\""<<x.ff<<"\" -> "<<x.snd<<endl;
        mx = max(mx, x.snd);
    }
    cout<<mx<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int t = 1;
    cin>>t;
    while (t--) {
        I_LOVE_PEREKOPSKA();
    }
}