#include using namespace std; const int mx =1e3+5; long long a[mx]; long long b[mx]; int n; long long getstart() { long long l = a[0],r=b[0]; for (int i=1;i=l && r>=a[i]) { l = max(l,a[i]); r = min(r,b[i]); } else { if (a[i]>r) return r; return l; } } return l; } int main() { int t; cin>>t; while (t--) { cin>>n; for (int i=0;i>a[i]>>b[i]; long long x1 = getstart(); long long x2 = x1,ans1=0,ans2=0; int flag = 0; for (int i=1;ix1) flag=1; } if (flag==1) { long long x3,x4; if (b[i]x1) { x3=a[i]; if (a[i]!=b[i]) x4=x3+1; else x4=x3; } else if (b[i]x2) { x4=a[i]; x3=x1; } else { x3=x1; x4=x2; } long long c,d,x,y; x=abs(x3-x1); y=abs(x3-x2); c = x/2 + x%2; d = y/2+y%2; // cout<