#include using namespace std; const int nmax=1e6+42; int n; pair inp[nmax]; int tree[nmax]; int query(int node,int l,int r,int lq,int rq) { if(l==lq&&r==rq)return tree[node]; int av=(l+r)/2; int ret=0; if(lq<=av)ret=max(ret,query(node*2,l,av,lq,min(av,rq))); if(av=i;k--) { update(1,0,n,inp[k+1].second,query(1,0,n,0,inp[k].second-1)+1); } i=j; } return tree[1]; } int main() { freopen("stairway.in","r",stdin); freopen("stairway.out","w",stdout); int t; scanf("%i",&t); while(t) { t--; printf("%i\n",2*solve()); } return 0; } /* 3 7 1 1 1 2 3 3 4 6 1 2 3 4 5 6 10 3 3 2 2 1 1 2 2 3 3 4 0 6 */