# include using namespace std; # define rep(i,a,n) for (int i=a; i<=n; ++i) # define per(i,a,n) for (int i=a; i>=n; --i) # define bug puts("H"); # define pb push_back # define mp make_pair # define all(x) (x).begin(), (x).end() # define SZ(x) (int)x.size() # define fi first # define se second # define lch p<<1,l,mid # define rch p<<1|1,mid+1,r # define mem(a,b) memset(a,b,sizeof(a)) # define INF 1000000001 # define MOD 1000000007 typedef vector Vi; typedef long long i64; typedef pair Pi; i64 powmod(i64 a, i64 b){i64 res=1;a%=MOD;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;} i64 Inv(i64 b){return powmod(b,(i64)MOD-2);} const int N = 100005; const double eps = 1e-9; const double inf = 1e18; vector a, b; map Mp; int main () { int T; scanf("%d", &T); while (T--) { int n, f, x, ans = 0; scanf("%d", &n); Mp.clear(); a.clear(); b.clear(); rep(i,1,n) { scanf("%d", &f); if (f == 2) scanf("%d", &x), a.pb(x); else scanf("%d", &x), b.pb(x), Mp[x] = 1, ans = max(ans, x+1); } for (auto i: a) { if (Mp.find(i+1) == Mp.end()) ans = max(ans, i+2), Mp[i+1] = 1; else ans = max(ans, i+3); } printf("%d\n", ans); } return 0; }