#include #define Max(a,b) ((ab)&&(a=b)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=hd[a],y;(y=to[i]);i=nxt[i]) using namespace std; typedef long long ll; char C; inline int rd() { int res=0,f=1; while(C=getchar(),C<48||C>57)if(C=='-')f=0; do res=(res<<3)+(res<<1)+(C^48); while(C=getchar(),C>=48&&C<=57); if(f)return res; return -res; } const int M=1e5+10; bool mk[M]; int b[M]; int main() { int T=rd(); while(T--) { memset(mk,0,sizeof mk); int n=rd(),ans=0,p2=0; rep(i,1,n) { int x=rd(),y=rd(); if(x==1)mk[y]=1,Max(ans,y+1); if(x==2)b[++p2]=y; } rep(i,1,p2) { if(mk[b[i]+1])Max(ans,b[i]+3); else Max(ans,b[i]+2); } cout<