#include #define cir(x) memset(x,0,sizeof(x)) #define LL long long using namespace std; const int N=1e3+10; int a[N],b[N]; int c[N],d[N]; int n,m,T; int main(){ scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",a+i,b+i); int ct = 0,l = a[1],r = b[1]; for(int i=2;i<=n;i++){ if(rb[i]){ c[++ct] = l; d[ct] = r; l = a[i]; r = b[i]; }else{ l=max(l,a[i]); r=min(r,b[i]); } } c[++ct] = l; d[ct] = r; int pos = c[1]; if(ct == 1){ printf("0\n"); continue; } if(d[1] < c[2]){ pos = d[1]; } LL ans = 0; for(int i=2;i<=ct;i++){ if(pos > d[i]){ if((pos - d[i]) %2 == 1 && d[i] - c[i] > 0 && i < ct && d[i+1] < c[i]){ ans += (pos - d[i] + 1) / 2; pos = d[i] - 1; } else{ ans += (pos - d[i] + 1) / 2; pos = d[i]; } }else { if((c[i] - pos) %2 == 1 && d[i] - c[i] > 0 && i < ct && c[i+1] > d[i]){ ans += (c[i] - pos + 1) / 2; pos = c[i] + 1; } else{ ans += (c[i] - pos + 1) / 2; pos = c[i]; } } } printf("%I64d\n",ans); } return 0; }