#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll DIM = 2*7e5+7;
vector<ll> Q[DIM];
ll a[DIM], b[DIM], c[DIM];
void solve(){
    ll n;
    cin >> n;
    vector<ll> Q[DIM];
    ll ans = 0;
    for(int i=1; i<=n; i++){
        cin >> a[i] >> b[i] >> c[i];
        Q[a[i]].push_back(c[i]);
        Q[b[i]+1].push_back(-c[i]);
        ans = max(ans, c[i]);
    }

    ll sum = 0;
    for(int i=1; i<=2*n; i++){
        for(auto x : Q[i]) sum += x;
        ans = max(ans, sum);
    }
    cout << ans << endl;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
