#include const int maxn = 1010; int t,n; int f[maxn][maxn << 2]; int a[maxn],b[maxn]; std::vector v; inline int calc(int x,int y){ if(x > y) std::swap(x,y); return v[y] - v[x] + 1 >> 1; } inline void down(int & x,int y){if(x > y)x = y;} inline int find(int x){ return std::lower_bound(v.begin(),v.end(),x) - v.begin(); } int main(){ std::ios::sync_with_stdio(false),std::cin.tie(0); std::cin >> t; while(t--){ std::cin >> n; v.clear(); for(int i=1;i<=n;++i){ std::cin >> a[i] >> b[i]; v.push_back(a[i]); v.push_back(b[i]); if(a[i] != b[i]) v.push_back(a[i] + 1), v.push_back(b[i] - 1); } std::sort(v.begin(),v.end()); v.erase(std::unique(v.begin(),v.end()),v.end()); for(int i=0;i