#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
/*
题意是要在[L,R]区间盖一个高为H的大楼。
如果盖楼之前在[L,R]区间上有楼房的高度<H,则要重新盖。
最终求要重新盖的楼层的高度。
*/
int t,n,l,r,h;
const int maxn=100000+5;
int mine[100005<<2];
int pot[1000005<<2];
int result;
void build(int l,int r,int pos)
{
if(l==r){
pot[pos]=-1;
mine[pos]=0;
return;
}
int mid=(l+r)>>1;
build(l,mid,pos<<1);
build(mid+1,r,pos<<1|1);
mine[pos]=min(mine[pos<<1],mine[pos<<1|1]);
}
void pushdown(int pos)
{
if(pot[pos]>=0){
pot[pos<<1]=pot[pos];
mine[pos<<1]=pot[pos];
pot[pos<<1|1]=pot[pos];
mine[pos<<1|1]=pot[pos];
pot[pos]=-2;
}
}
void change(int a,int b,int h,int l,int r,int pos)
{
if(mine[pos]>h)return;
if(a<=l&&b>=r){
if(pot[pos]<=h&&pot[pos]!=-2){
result+=r-l+1;
pot[pos]=mine[pos]=h;
return;
}
}
pushdown(pos);
int mid=(l+r)>>1;
if(a<=mid)change(a,b,h,l,mid,pos<<1);
if(b>mid)change(a,b,h,mid+1,r,pos<<1|1);
mine[pos]=min(mine[pos<<1],mine[pos<<1|1]);
}
int main()
{
scanf("%d",&t);
while(t--){
result=0;
build(1,maxn,1);
pot[1]=0;
scanf("%d",&n);
while(n--){
scanf("%d%d%d",&l,&r,&h);
change(l,r-1,h,1,maxn,1);
}
printf("%d\n",result);
}
}