#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define sz(c) int((c).size())
#define fr(i,s,e) for(int i = s;i<e;i++)
#define testcase ll test_case;scanf("%lld",&test_case);fr(t,1,test_case+1)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define xx first
#define yy second
typedef vector<ll> vi;
typedef vector<vi> vii;
typedef pair<ll, ll> ii;
class node
{
public:
ll st,en,pr;
};
bool cmp(node& a,node& b)
{
if(a.st == b.st)
return a.pr>b.pr;
return a.st<b.st;
}
bool cmp2(ll n,node& a)
{
return a.st>n;
}
vi dp;
ll func(vector<node>& v,ll pos)
{
if(pos >=sz(v)) return 0;
if(dp[pos] != -1) return dp[pos];
ll ind = upper_bound(all(v),v[pos].en,cmp2)-v.begin();
//cout<<ind<<endl;
dp[pos] = v[pos].pr+func(v,ind);
ll n = func(v,pos+1);
return max(dp[pos],n);
}
int main()
{
freopen("tr_input.txt","r",stdin);
testcase
{
ll n;
cin>>n;
vector<node> v(n);
fr(i,0,n)
{
ll a,b,c;
cin>>a>>b>>c;
v[i] = {a,a+b-1,c};
}
dp.assign(n,-1);
sort(all(v),cmp);
cout<<func(v,0)<<endl;
/*for(auto i: dp) cout<<i<<" ";
for(auto i: v){
cout<<i.st<<" "<<i.en<<" "<<i.pr<<endl;
}*/
}
return 0;
}