#include using namespace std; inline int read(){ int x=0,f=1;char cc=getchar(); while(cc<'0' || cc>'9') {if(cc=='-') f=-1;cc=getchar();} while(cc>='0' && cc<='9') {x=x*10+cc-'0';cc=getchar();} return x*f; } int n,a[1010],b[1010],f[1000010],v[1000010]; vector s[2]; int main(){ for(int tt=read();tt;tt--){ n=read(); for(int i=1;i<=n;i++){ a[i]=read();b[i]=read(); } s[0].clear(); int x=0;int l=1;int r=1000000; while(x