#include<iostream>
#include<algorithm>
using namespace std;
struct job{
int start,finish,profit;
};
bool func(job s1,job s2){
return (s1.start<s2.start);
}
int binsearch(job a[],int st,int en,int val){
while(st<en){
int mid=(st+en)/2;
if(a[mid].start>=val)
en=mid;
else
st=mid+1;
}
if(a[st].start >=val) return st;
else return -1;
}
int main(){
int t,n,d,mm,m1;
cin>>t;
while(t--){
cin>>n;
job ar[n];
int pro[n+1]={0},m;
for(int i=0;i<n;i++){
cin>>ar[i].start>>d>>ar[i].profit;
ar[i].finish=ar[i].start+d;
}
/*r(int i=0;i<n;i++)
cout<<ar[i].start<<" "<<ar[i].finish<<" "<<ar[i].profit<<endl;*/
sort(ar,ar+n,func);
for(int i=n-1;i>=0;i--){
pro[i]=pro[i+1];
mm=binsearch(ar,i+1,n-1,ar[i].finish);
if(mm==-1) m1=0;
else m1=pro[mm];
if(m1+ar[i].profit > pro[i])
pro[i]=pro[mm]+ar[i].profit;
}
cout<<pro[0]<<endl;
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IGpvYnsKCWludCBzdGFydCxmaW5pc2gscHJvZml0Owp9Owpib29sIGZ1bmMoam9iIHMxLGpvYiBzMil7CglyZXR1cm4gKHMxLnN0YXJ0PHMyLnN0YXJ0KTsKfQppbnQgYmluc2VhcmNoKGpvYiBhW10saW50IHN0LGludCBlbixpbnQgdmFsKXsKCXdoaWxlKHN0PGVuKXsKCQlpbnQgbWlkPShzdCtlbikvMjsKCQlpZihhW21pZF0uc3RhcnQ+PXZhbCkKCQkJZW49bWlkOwoJCWVsc2UKCQkJc3Q9bWlkKzE7Cgl9CglpZihhW3N0XS5zdGFydCA+PXZhbCkgcmV0dXJuIHN0OwoJZWxzZSByZXR1cm4gLTE7Cn0KaW50IG1haW4oKXsKCWludCB0LG4sZCxtbSxtMTsKCWNpbj4+dDsKCXdoaWxlKHQtLSl7CgkJ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