#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[maxn]={0},b[maxn]={0};
		int minia=1e10,minib = 1e10;
		for(int i = 1;i <= n; i ++)
		{
			cin>>a[i];
			minia = min(minia,a[i]);
		}
		for(int i = 1;i <= n; i ++)
		{
			cin>>b[i];
			minib = min(minib,b[i]);
		}
		long long ans = 0;
		for(int i = 1;i <= n; i ++)
		{
			ans+=max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int minia=0x3fff,minib=0x3fff;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			minia=min(a[i],minia);
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			minib=min(b[i],minib);
		}
		long long ans = 0;
		for(int i=1;i<=n;i++)
		{
			while(a[i]>minia&&b[i]>minib) {
				ans++;
				a[i]--;
				b[i]--;
			}
			ans=ans+(a[i]-minia)+(b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int minia=1e8,minib = 1e8;
		for(int i = 1;i <= n; i ++)
		{
			cin>>a[i];
			minia = min(minia,a[i]);
		}
		for(int i = 1;i <= n; i ++)
		{
			cin>>b[i];
			minib = min(minib,b[i]);
		}
		long long ans = 0;
		for(int i = 1;i <= n; i ++)
		{
			ans+=max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[maxn],b[maxn];
		int minia=1e8,minib = 1e8;
		for(int i = 1;i <= n; i ++)
		{
			cin>>a[i];
			minia = min(minia,a[i]);
		}
		for(int i = 1;i <= n; i ++)
		{
			cin>>b[i];
			minib = min(minib,b[i]);
		}
		long long ans = 0;
		for(int i = 1;i <= n; i ++)
		{
			ans+=max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[maxn]={0},b[maxn]={0};
		int minia=1<<30,minib=1<<30;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			minia=min(a[i],minia);
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			minib=min(b[i],minib);
		}
		long long ans = 0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]>minia&&b[i]>minib) {
				int aa=min(a[i]-minia,b[i]-minib);
				ans+=aa;
				a[i]-=aa;
				b[i]-=aa;
			}
			ans=ans+(a[i]-minia)+(b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int minia=0x3fff,minib=0x3fff;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			minia=min(a[i],minia);
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			minib=min(b[i],minib);
		}
		long long ans = 0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]>minia&&b[i]>minib) {
				int aa=min(a[i]-minia,b[i]-minib);
				ans+=aa;
				a[i]-=aa;
				b[i]-=aa;
			}
			ans=ans+(a[i]-minia)+(b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int minia=1<<28,minib=1<<28;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			minia=min(a[i],minia);
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			minib=min(b[i],minib);
		}
		long long ans = 0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]>minia&&b[i]>minib) {
				int aa=min(a[i]-minia,b[i]-minib);
				ans+=aa;
				a[i]-=aa;
				b[i]-=aa;
			}
			ans=ans+(a[i]-minia)+(b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  int t;
  cin >> t;
  while(t--)
  {
    int n,x;
    cin >> n;
    vector<long int> a,b;
    for(int i=0;i<n;i++)
    {
      cin >> x;
      a.push_back(x);
    }
    for(int i=0;i<n;i++)
    {
      cin >> x;
      b.push_back(x);
    }
    vector<long int>c=a,d=b;
    sort(c.begin(),c.end());
    sort(d.begin(),d.end());

    long int ans=0;
    for(int i=0;i<n;i++)
      ans += max(a[i]-c[0],b[i]-d[0]);
    cout << ans << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;

long int a1,b1;
long int fun(vector<long int> a,vector<long int> b,long int i,long int n);
int main()
{
  long int t;
  cin >> t;
  while(t--)
  {
    long int n,x;
    cin >> n;
    vector<long int> a,b;
    for(long int i=0;i<n;i++)
    {
      cin >> x;
      a.push_back(x);
    }
    for(long int i=0;i<n;i++)
    {
      cin >> x;
      b.push_back(x);
    }
    a1 = *min_element(a.begin(),a.end());
    b1 = *min_element(b.begin(),b.end());
    cout << fun(a,b,0,n-1) << endl;
  }
}

long int fun(vector<long int> a,vector<long int> b,long int i,long int n)
{
  if(i<=n)
    return max(a[i]-a1,b[i]-b1)+fun(a,b,i+1,n);

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  int t;
  cin >> t;
  while(t--)
  {
    int n,x;
    cin >> n;
    vector<long int> a,b;
    for(int i=0;i<n;i++)
    {
      cin >> x;
      a.push_back(x);
    }
    for(int i=0;i<n;i++)
    {
      cin >> x;
      b.push_back(x);
    }
    long int a1 = *min_element(a.begin(),a.end());
    long int b1 = *min_element(b.begin(),b.end());
    long int ans=0;
    for(int i=0;i<n;i++)
      ans += max(a[i]-a1,b[i]-b1);
    cout << ans << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;

int a1,b1;
long int fun(vector<int> a,vector<int> b,int i,int n);
int main()
{
  int t;
  cin >> t;
  while(t--)
  {
    int n,x;
    cin >> n;
    vector<int> a,b;
    for(int i=0;i<n;i++)
    {
      cin >> x;
      a.push_back(x);
    }
    for(int i=0;i<n;i++)
    {
      cin >> x;
      b.push_back(x);
    }
    a1 = *min_element(a.begin(),a.end());
    b1 = *min_element(b.begin(),b.end());
    cout << fun(a,b,0,n-1) << endl;
  }
}

long int fun(vector<int> a,vector<int> b,int i,int n)
{
  if(i<=n)
    return max(a[i]-a1,b[i]-b1)+fun(a,b,i+1,n);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
	  int n,x,y;
    cin >> n;
    vector<int> a,b;
    for(int i=0;i<n;i++)
    {
      cin >> x;
      a.push_back(x);
    }
    for(int i=0;i<n;i++)
    {
      cin >> x;
      b.push_back(x);
    }
    x=*min_element(a.begin(),a.end());
    y=*min_element(b.begin(),b.end());
    unsigned long long sum=0;
    for(int i=0;i<n;i++)
    {
      sum=sum+max(a[i]-x,b[i]-y);
    }
    cout<<sum<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

int a1,b1;
long int fun(vector<int> a,vector<int> b,int i,int n);
int main()
{
  int t;
  cin >> t;
  while(t--)
  {
    int n,x;
    cin >> n;
    vector<int> a,b;
    for(int i=0;i<n;i++)
    {
      cin >> x;
      a.push_back(x);
    }
    for(int i=0;i<n;i++)
    {
      cin >> x;
      b.push_back(x);
    }
    a1 = *min_element(a.begin(),a.end());
    b1 = *min_element(b.begin(),b.end());
    cout << fun(a,b,0,n-1) << endl;
  }
}

long fun(vector<int> a,vector<int> b,int i,int n)
{
  if(i<=n)
    return max(a[i]-a1,b[i]-b1)+fun(a,b,i+1,n);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int n;
        cin>>n;
        int C[n],O[n];
        int c=0,o=0;
        for(int i=0;i<n;i++)
        {
            cin>>C[i];
            if(C[i]<C[c])
            {
                c=i;
            }
        }
        for(int i=0;i<n;i++)
        {
            cin>>O[i];
            if(O[i]<O[o])
            {
                o=i;
            }
        }

        int moves=0;
        for(int i=0;i<n;i++)
        {
          moves+=max(C[i]-C[c],O[i]-O[o]);
        }
        cout<<moves<<char(10);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int n;
        cin>>n;
        long long int C[n],O[n];
        int c=0,o=0;
        for(int i=0;i<n;i++)
        {
            cin>>C[i];
            if(C[i]<C[c])
            {
                c=i;
            }
        }
        for(int i=0;i<n;i++)
        {
            cin>>O[i];
            if(O[i]<O[o])
            {
                o=i;
            }
        }

        long long int moves=0;
        for(int i=0;i<n;i++)
        {
          moves+=max(C[i]-C[c],O[i]-O[o]);
        }
        cout<<moves<<char(10);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int n;
        cin>>n;
        vector<long long int>C(n),O(n);
        int c=0,o=0;
        for(int i=0;i<n;i++)
        {
            cin>>C[i];
            if(C[i]<C[c])
            {
                c=i;
            }
        }
        for(int i=0;i<n;i++)
        {
            cin>>O[i];
            if(O[i]<O[o])
            {
                o=i;
            }
        }

        long long int moves=0;
        for(int i=0;i<n;i++)
        {
          moves+=max(C[i]-C[c],O[i]-O[o]);
        }
        cout<<moves<<char(10);
    }

    return 0;
}


#include<bis/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int n;
        cin>>n;
        int C[n];
        int O[n];
        int c=0;
        int o=0;
        for(int i=0;i<n;i++)
        {
            cin>>C[i];
            if(C[i]<C[c])
            {
                c=i;
            }
        }
        for(int i=0;i<n;i++)
        {
            cin>>O[i];
            if(O[i]<O[o])
            {
                o=i;
            }
        }

        int moves=0;
        for(int i=0;i<n;i++)
        {
          moves+=max(C[i]-C[c],O[i]-O[o]);
        }
        cout<<moves<<char(10);
    }

    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int t;
    cin>>t;

    while(t--)
    {
        int n;
        cin>>n;
        int C[n];
        int O[n];
        int c=0;
        int o=0;
        for(int i=0;i<n;i++)
        {
            cin>>C[i];
            if(C[i]<C[c])
            {
                c=i;
            }
        }
        for(int i=0;i<n;i++)
        {
            cin>>O[i];
            if(O[i]<O[o])
            {
                o=i;
            }
        }

        int moves=0;
        for(int i=0;i<n;i++)
        {
            while(!(C[i]==C[c] and O[i]==O[o]))
            {
                if(C[i]>C[c] and O[i]>O[o])
                {
                    // moves++;
                    C[i]--;
                    O[i]--;
                }
                else if(C[i]>C[c])
                {
                    // moves++;
                    C[i]--;
                }
                else if(O[i]>O[o])
                {
                    // moves++;
                    O[i]--;
                }
                moves++;
            }
        }

        cout<<moves<<char(10);
    }

    return 0;
}


#include<iostream>
using namespace std;

int answer(int a[100][100],int b[100][100], int index, int n)
{
	int mina, minb,q=0,count=0,i;
	mina=a[index][0];
	minb=b[index][0];

	for(i=0;i<n;i++)
	{
	if(mina>a[index][i])
	mina=a[index][i];
	if(minb>b[index][i])
	minb=b[index][i];
	}
	i=0;
	do{
	if(a[index][i]>mina&&b[index][i]>minb)
	{
		count++;
		a[index][i]-=1;
		b[index][i]-=1;
	}
	else
	if(a[index][i]>mina)
	{
		count++;
		a[index][i]-=1;
	}
	else
	if(b[index][i]>minb)
	{
		count++;
		b[index][i]-=1;
	}
	else
	if(a[index][i]==mina&&b[index][i]==minb)
	{
	i++;
	q++;
	}

	}while(q!=n);
	return count;
}

int main()
{

	int t,n,a[100][100],b[100][100],ans[100];
	cin>>t;
	for(int i=0;i<t;i++)
	{
		cin>>n;
		for(int j=0;j<n;j++)
			cin>>a[i][j];
		for(int j=0;j<n;j++)
			cin>>b[i][j];

		ans[i]=answer(a,b,i,n);

	}

	for(int i=0;i<t;i++)
	cout<<ans[i]<<endl;
}


#include<iostream>
using namespace std;

long long int answer(int a[100][100],int b[100][100], int index, int n)
{
	unsigned int mina, minb,q=0,i,x;
	long long int count=0;
	mina=a[index][0];
	minb=b[index][0];

	for(i=0;i<n;i++)
	{
	if(mina>a[index][i])
	mina=a[index][i];
	if(minb>b[index][i])
	minb=b[index][i];
	}
	i=0;
	do{
	if(a[index][i]>mina&&b[index][i]>minb)
	{
		if((a[index][i]-mina)>(b[index][i]-minb))
		{
			x=b[index][i]-minb;
			count+=x;
			a[index][i]-=x;
			b[index][i]-=x;
		}
		else
		{
			x=a[index][i]-mina;
			count+=x;
			a[index][i]-=x;
			b[index][i]-=x;
		}
	}
	else
	if(a[index][i]>mina)
	{
		x=a[index][i]-mina;
		count+=x;
		a[index][i]-=x;
	}
	else
	if(b[index][i]>minb)
	{
		x=b[index][i]-minb;
		count+=x;
		b[index][i]-=x;
	}
	else
	if(a[index][i]==mina&&b[index][i]==minb)
	{
	i++;
	}

	}while(i<n);
	return count;
}

int main()
{

	int t,n,a[100][100],b[100][100];
	long long int ans[100];
	cin>>t;
	for(int i=0;i<t;i++)
	{
		cin>>n;
		for(int j=0;j<n;j++)
			cin>>a[i][j];
		for(int j=0;j<n;j++)
			cin>>b[i][j];

		ans[i]=answer(a,b,i,n);

	}

	for(int i=0;i<t;i++)
	cout<<ans[i]<<endl;
}


#include<iostream>
using namespace std;

long long int answer(long long int a[1000][1000],long long int b[1000][100], int index, int n)
{
	long long int mina, minb,q=0,i,x;
	long long int count=0;
	mina=a[index][0];
	minb=b[index][0];

	for(i=0;i<n;i++)
	{
	if(mina>a[index][i])
	mina=a[index][i];
	if(minb>b[index][i])
	minb=b[index][i];
	}
	i=0;
	do{
	if(a[index][i]>mina&&b[index][i]>minb)
	{
		if((a[index][i]-mina)>(b[index][i]-minb))
		{
			x=b[index][i]-minb;
			count+=x;
			a[index][i]-=x;
			b[index][i]-=x;
		}
		else
		{
			x=a[index][i]-mina;
			count+=x;
			a[index][i]-=x;
			b[index][i]-=x;
		}
	}
	else
	if(a[index][i]>mina)
	{
		x=a[index][i]-mina;
		count+=x;
		a[index][i]-=x;
	}
	else
	if(b[index][i]>minb)
	{
		x=b[index][i]-minb;
		count+=x;
		b[index][i]-=x;
	}
	else
	if(a[index][i]==mina&&b[index][i]==minb)
	{
	i++;
	}

	}while(i<n);
	return count;
}

int main()
{

	long long int t,n,a[1000][1000],b[1000][100];
	long long int ans[1000];
	cin>>t;
	for(int i=0;i<t;i++)
	{
		cin>>n;
		for(int j=0;j<n;j++)
			cin>>a[i][j];
		for(int j=0;j<n;j++)
			cin>>b[i][j];

		ans[i]=answer(a,b,i,n);

	}

	for(int i=0;i<t;i++)
	cout<<ans[i]<<endl;
}


#include<iostream>
using namespace std;

long long int answer(long long int a[100][100],long long int b[100][100], int index, int n)
{
	long long int mina, minb,q=0,i,x;
	long long int count=0;
	mina=a[index][0];
	minb=b[index][0];

	for(i=0;i<n;i++)
	{
	if(mina>a[index][i])
	mina=a[index][i];
	if(minb>b[index][i])
	minb=b[index][i];
	}
	i=0;
	do{
	if(a[index][i]>mina&&b[index][i]>minb)
	{
		if((a[index][i]-mina)>(b[index][i]-minb))
		{
			x=b[index][i]-minb;
			count+=x;
			a[index][i]-=x;
			b[index][i]-=x;
		}
		else
		{
			x=a[index][i]-mina;
			count+=x;
			a[index][i]-=x;
			b[index][i]-=x;
		}
	}
	else
	if(a[index][i]>mina)
	{
		x=a[index][i]-mina;
		count+=x;
		a[index][i]-=x;
	}
	else
	if(b[index][i]>minb)
	{
		x=b[index][i]-minb;
		count+=x;
		b[index][i]-=x;
	}
	else
	if(a[index][i]==mina&&b[index][i]==minb)
	{
	i++;
	}

	}while(i<n);
	return count;
}

int main()
{

	long long int t,n,a[100][100],b[100][100];
	long long int ans[100];
	cin>>t;
	for(int i=0;i<t;i++)
	{
		cin>>n;
		for(int j=0;j<n;j++)
			cin>>a[i][j];
		for(int j=0;j<n;j++)
			cin>>b[i][j];

		ans[i]=answer(a,b,i,n);

	}

	for(int i=0;i<t;i++)
	cout<<ans[i]<<endl;
}


#include<iostream>
using namespace std;

int answer(int a[100][100],int b[100][100], int index, int n)
{
	int mina, minb,q=0,count=0,i;
	mina=a[index][0];
	minb=b[index][0];

	for(i=0;i<n;i++)
	{
	if(mina>a[index][i])
	mina=a[index][i];
	if(minb>b[index][i])
	minb=b[index][i];
	}
	i=0;
	do{
	if(a[index][i]>mina&&b[index][i]>minb)
	{
		count++;
		a[index][i]-=1;
		b[index][i]-=1;
	}
	else
	if(a[index][i]>mina)
	{
		count++;
		a[index][i]-=1;
	}
	else
	if(b[index][i]>minb)
	{
		count++;
		b[index][i]-=1;
	}
	else
	if(a[index][i]==mina&&b[index][i]==minb)
	{
	i++;
	q++;
	}

	}while(q!=n);
	return count;
}

int main()
{

	int t,n,a[100][100],b[100][100];
	cin>>t;
	for(int i=0;i<t;i++)
	{
		cin>>n;
		for(int j=0;j<n;j++)
			cin>>a[i][j];
		for(int j=0;j<n;j++)
			cin>>b[i][j];

		cout<<answer(a,b,i,n);

	}

}


#include<iostream>

using namespace std;

int main()
{
    int t;
    int n;
    long long int min1;
    long long int min2;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        int c = 0;
        int cnt = 0;
        long long int a[n],b[n];
        for(int j=0;j<n;j++)
        {
           cin>>a[j];
        }
        for(int k=0;k<n;k++)
        {
           cin>>b[k];
        }
        for(int m=0;m<n;m++)
        {
            if(a[m]==b[m])
             c++;
            else
            {
                min1 = a[0];
                min2=b[0];
                for(int x=0;x<n;x++)
               {
                   if(a[x]<min1)
                    min1 = a[x];
                }
                for(int y=0;y<n;y++)
               {
                  if(b[y]<min2)
                    min2 = b[y];
               }
               if(a[m]!=min1)
               {
                   while(a[m]!=min1)
                   {
                       a[m] = a[m] - 1;
                       cnt++;
                   }

               }
               if(b[m]!=min2)
               {
                   while(b[m]!=min2)
                   {
                       b[m] = b[m] - 1;
                       cnt++;
                   }

               }
            }
        }
        if(c==n)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<cnt<<endl;
        }
    }
}


#inlcude<iostream>

using namespace std;

int main()
{
    int t;
    int n;
    int cnt=0;
    int c=0;
    long int min1;
    long int min2;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        long int a[n],b[n];
        for(int j=0;j<n;j++)
        {
           cin>>a[j];
        }
        for(int k=0;k<n;k++)
        {
           cin>>b[k];
        }
        for(int m=0;m<n;m++)
        {
            if(a[m]==b[m])
             c++;
            else
            {
                min1 = a[0];
                min2=b[0];
                for(int x=0;x<n;x++)
               {
                   if(a[x]<min1)
                    min1 = a[x];
                }
                for(int y=0;y<n;y++)
               {
                  if(b[y]<min2)
                    min2 = b[y];
               }
               if(a[m]!=min1)
               {
                   while(a[m]!=min1)
                   {
                       a[m] = a[m] - 1;
                   }
                   cnt++;
               }
               if(b[m]!=min2)
               {
                   while(b[m]!=min2)
                   {
                       b[m] = b[m] - 1;
                   }
                   cnt++;
               }
            }
        }
        if(c==n)
        {
            cout<<0;
        }
        else
        {
            cout<<cnt;
        }
    }
}


#include<iostream>

using namespace std;

int main()
{
    int t;
    int n;
    int cnt=0;
    int c=0;
    long int min1;
    long int min2;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        long int a[n],b[n];
        for(int j=0;j<n;j++)
        {
           cin>>a[j];
        }
        for(int k=0;k<n;k++)
        {
           cin>>b[k];
        }
        for(int m=0;m<n;m++)
        {
            if(a[m]==b[m])
             c++;
            else
            {
                min1 = a[0];
                min2=b[0];
                for(int x=0;x<n;x++)
               {
                   if(a[x]<min1)
                    min1 = a[x];
                }
                for(int y=0;y<n;y++)
               {
                  if(b[y]<min2)
                    min2 = b[y];
               }
               if(a[m]!=min1)
               {
                   while(a[m]!=min1)
                   {
                       a[m] = a[m] - 1;
                   }
                   cnt++;
               }
               if(b[m]!=min2)
               {
                   while(b[m]!=min2)
                   {
                       b[m] = b[m] - 1;
                   }
                   cnt++;
               }
            }
        }
        if(c==n)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<cnt<<endl;
        }
    }
}


#include<bits/stdc++.h>
typedef long long ll;
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>v;
        for(ll i=0; i<n; i++)
        {
            ll x;
            cin>>x;
            v.push_back(x);
        }
        ll gn=1,f=0;
        for(ll i=0;i<n;i++)
        {
            if(v[i]==1)
            {
                f=1;
                gn++;
            }
        }

        if(f==0)
        {
            cout<<1<<endl;
        }
        else
        {
            ll z=0,i,j,cnt=-1,mx=0;
            ll y=gn,gn1=gn;
            for(i=0;i<n;i++)
            {
                if(v[i]!=1)
                {
                    mx=max(mx,v[i]);
                    if(v[i]>y)
                    {
                        cnt++;
                        y=cnt+gn;
                        //cout<<y<<" y "<<v[i]<<endl;
                        if(mx<=y)
                        {
                            gn+=cnt+1;
                            cnt=-1;
                        }
                    }
                    else
                    {
                        gn++;
                    }
                }
            }

            //2nd

            ll z1=0,i1,j1,cnt1=-1,mx1=0;
            ll y1=gn1;
            for(i1=n-1;i1>=0;i1--)
            {
                if(v[i1]!=1)
                {
                    mx1=max(mx1,v[i1]);
                    if(v[i1]>y1)
                    {
                        cnt1++;
                        y1=cnt1+gn1;
                        //cout<<y1<<" y "<<v[i1]<<endl;
                        if(mx1<=y1)
                        {
                            gn1+=cnt1+1;
                            cnt1=-1;
                        }
                    }
                    else
                    {
                        gn1++;
                    }
                }
            }

            //cout<<gn<<" "<<gn1<<endl;

            cout<<max(gn,gn1)<<endl;
        }

    }

    return 0;

}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int arr[n];
        int cnt[2*N];
        mem(cnt,0);
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            cnt[arr[i]]++;
        }
        int zero = 0;
        int ans =0;
        for(int i=1;i<=10;i++)
        {
            zero++;
            if(cnt[i]!=0)
            {
                zero -= cnt[i];
            }
            //cout << i << " " << zero << " " << cnt[i] << "\n";
            if(zero<=0)
                ans = i;
        }
        cout << ans+1 << "\n";
    }
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int arr[n];
        int cnt[2*N];
        mem(cnt,0);
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            cnt[arr[i]]++;
        }
        int zero = 0;
        int ans =0;
        for(int i=1;i<=2*N;i++)
        {
            zero++;
            if(cnt[i]!=0)
                zero -= cnt[i];
            //cout << i << " " << zero << " " << cnt[i] << "\n";
            if(zero==0)
                ans = i;
        }
        cout << ans+1 << "\n";
    }
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int arr[n];
        int cnt[2*N];
        mem(cnt,0);
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            cnt[arr[i]]++;
        }
        int zero = 0;
        int ans =0;
        for(int i=1;i<=2*N;i++)
        {
            zero++;
            zero -= cnt[i];
            ////cout << i << " " << zero << " " << cnt[i] << "\n";
            if(zero<=0)
                ans = i;
        }
        cout << ans+1 << "\n";
    }
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int arr[n];
        int cnt[2*N];
        mem(cnt,0);
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            cnt[arr[i]]++;
        }
        int left=0;
        int extra = 0;
        int ans = 1;
        for(int i=1;i<=10;i++)
        {
            if(left==0)
            {
                if(cnt[i]!=0)
                {
                    ans++;
                    extra += cnt[i]-1;
                }
                else
                {
                    if(extra==0)
                        left++;
                    else
                    {
                        ans++;
                        extra--;
                    }
                }
            }
            else
            {
                if(cnt[i]==0)
                    left++;
                else
                {
                    left++;
                    if(cnt[i]>=left)
                    {
                        cnt[i] -= left;
                        ans += left;
                        left = 0;
                    }
                    else
                    {
                        left -= cnt[i];
                        cnt[i]=0;
                    }
                }
            }
            //cout << i << " " << left << " " << cnt[i] << " " << "\n";
            if(left==0)
                ans = i+1;
        }
        cout << ans << "\n";
    }
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int arr[n];
        int cnt[2*N];
        mem(cnt,0);
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            cnt[arr[i]]++;
        }
        int zero = 0;
        int ans =0;
        for(int i=1;i<=2*N;i++)
        {
            zero++;
            if(cnt[i]!=0)
                zero -= cnt[i];
            //cout << i << " " << zero << " " << cnt[i] << "\n";
            if(zero<=0)
                ans = i;
        }
        cout << ans+1 << "\n";
    }
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int arr[n];
        int cnt[2*N];
        mem(cnt,0);
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            cnt[arr[i]]++;
        }
        int zero = 0;
        int ans =0;
        for(int i=1;i<=2*N;i++)
        {
            zero++;
            zerp -= cnt[i];
            //cout << i << " " << zero << " " << cnt[i] << "\n";
            if(zero<=0)
                ans = i;
        }
        cout << ans+1 << "\n";
    }
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int arr[n];
        int cnt[2*N];
        mem(cnt,0);
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            cnt[arr[i]]++;
        }
        int zero = 0;
        int ans =0;
        for(int i=1;i<=2*N;i++)
        {
            zero++;
            zero -= cnt[i];
            //cout << i << " " << zero << " " << cnt[i] << "\n";
            if(zero<=0)
                ans = i;
        }
        cout << ans+1 << "\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long i,n,t,j,x,y,sum,s,m,c,k,d,f;
    long long a[300000];
    scanf("%lld",&t);
    for(j=0; j<t; j++)
    {
       scanf("%lld",&n);
       for(i=1;i<=n;i++)
       {
           scanf("%lld",&a[i]);
       }
  sort(a+1,a+n+1);
x=0;m=-1;
      for(i=n;i>=1;i--)
       {
           if(i>=a[i])
            {x=i;m=0;break;}
       }
      if(m==0) {printf("%lld\n",x+1);}
      else{printf("1\n");}
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long i,n,t,j,x,y,sum,s,m,c,k,d,f;
    char a[200000];
    scanf("%lld",&t);
    for(j=0; j<t; j++)
    {
       scanf("%lld",&n);
       for(i=1;i<=n;i++)
       {
           scanf("%lld",&a[i]);
       }
       x=0;
  sort(a+1,a+n+1);

      for(i=n;i>=1;i--)
       {
           if(i>=a[i])
            {x=i;break;}
       }
       printf("%lld\n",x+1);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long i,n,t,j,x,y,sum,s,m,c,k,d,f;
    char a[300000];
    scanf("%lld",&t);
    for(j=0; j<t; j++)
    { x=0;
       scanf("%lld",&n);
       for(i=1;i<=n;i++)
       {
           scanf("%lld",&a[i]);
       }

  sort(a+1,a+n+1);

      for(i=n;i>=1;i--)
       {
           if(i>=a[i])
            {x=i;break;}
       }
       printf("%lld\n",x+1);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long i,n,t,j,x,y,sum,s,m,c,k,d,f;
    char a[300000];
    scanf("%lld",&t);
    for(j=0; j<t; j++)
    {
       scanf("%lld",&n);
       for(i=1;i<=n;i++)
       {
           scanf("%lld",&a[i]);
       }
  sort(a+1,a+n+1);
x=0;m=-1;
      for(i=n;i>=1;i--)
       {
           if(i>=a[i])
            {x=i;m=0;break;}
       }
      if(m==0) {printf("%lld\n",x+1);}
      if(m==-1){printf("1\n");}
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long i,n,t,j,x,y,sum,s,m,c,k,d,f;
    char a[300000];
    scanf("%lld",&t);
    for(j=0; j<t; j++)
    {
       scanf("%lld",&n);
       for(i=1;i<=n;i++)
       {
           scanf("%lld",&a[i]);
       }
  sort(a+1,a+n+1);
x=1;m=-1;
      for(i=n;i>=1;i--)
       {
           if(i>=a[i])
            {x=i;m=0;break;}
       }
      if(m==0) {printf("%lld\n",x+1);}
      else{printf("1\n");}
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long i,n,t,j,x,y,sum,s,m,c,k,d,f;
    char a[200000];
    scanf("%lld",&t);
    for(j=0; j<t; j++)
    {
       scanf("%lld",&n);
       for(i=1;i<=n;i++)
       {
           scanf("%lld",&a[i]);
       }
  sort(a+1,a+1+n);
  x=0;
      for(i=1;i<=n;i++)
       {
           if(i>=a[i])
            x=i;
       }
       printf("%lld\n",x+1);
    }

    return 0;
}


#include <iostream>
#include<string>
#include <sstream>
#include<vector>
#include<bits/stdc++.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

int main ()
{
int n,t,sum,occ,c,x;
cin>>t;

while(t--)
{

    cin>>n;

    int a[n];

    for(int i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);
c=0;
     sum=1;
  for(int i=0;i<n;i++)
  {

        if(a[i]>n)
            break;

        occ=count(a, a + n, a[i]);

        x=(occ-1)+sum+(i-c);
      if(a[i]<=sum)
      {
        sum++;
       c++;
      }

      else if((x)>=(a[i]))

              {

                  sum=x+1;
                  i=i+occ;
                    c=0;

              }

  }

    cout<<sum<<endl;
}

}


#include <iostream>
#include<string>
#include <sstream>
#include<vector>
#include<bits/stdc++.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

int main ()
{
int n,t,sum,occ,c,x;
cin>>t;

while(t--)
{

    cin>>n;

    int a[n];

    for(int i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);
    c=0;
    sum=1;
  for(int i=0;i<n;i++)
  {

        occ=count(a, a + n, a[i]);

        x=occ+c+sum-1;

      if(a[i]<=sum)
      {
        sum++;
        c=0;
      }

      else if((x)>=(a[i]))

              {
                  sum=sum+occ+c;
                  i=i+occ+1;
              }
      else
        c++;

  }

    cout<<sum<<endl;
}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,i,m=0;
		cin>>n;
		int a[n];
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		sort(a,a+n);
		for(i=0;i<n;i++)
		{
			if(i+1>=a[i])
			m=i+1;
		}
		cout<<m+1<<"\n";
	}
}


#include <iostream>
#include<string>
#include <sstream>
#include<vector>
#include<bits/stdc++.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

int main ()
{
int n,t,sum,occ,index,x;
cin>>t;

while(t--)
{

    cin>>n;

    int a[n];

    for(int i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);
     index =a[n-1];
     sum=1;
  for(int i=0;i<n;i++)
  {

        occ=count(a, a + n, a[i]);

        x=(occ-1)+sum+(i-index-1);

      if(a[i]<=sum)
      {
        sum++;
        index=i;
      }

      else if((x)>=(a[i]))

              {
                  cout<<i;
                  sum=x+1;
                  i=i+occ;

              }

  }

    cout<<sum<<endl;
}

}


#include <iostream>
#include<string>
#include <sstream>
#include<vector>
#include<bits/stdc++.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

int main ()
{
int n,t,sum,occ,index,x;
cin>>t;

while(t--)
{

    cin>>n;

    int a[n];

    for(int i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);
     index =a[n-1];
     sum=1;
  for(int i=0;i<n;i++)
  {

        occ=count(a, a + n, a[i]);

        x=(occ-1)+sum+(i-index-1);

      if(a[i]<=sum)
      {
        sum++;
        index=i;
      }

      else if((x)>=(a[i]))

              {

                  sum=x+1;
                  i=i+occ;

              }

  }

    cout<<sum<<endl;
}

}


#include <iostream>
#include<string>
#include <sstream>
#include<vector>
#include<bits/stdc++.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

int main ()
{
int n,t,sum,occ,x;
cin>>t;

while(t--)
{

    cin>>n;

    int a[n];

    for(int i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);

     sum=1;
  for(int i=0;i<n;i++)
  {

        occ=count(a, a + n, a[i]);

        x=occ+i-1;
      if(a[i]<=sum)
      {
        sum++;

      }

      else if((x)>=(a[i]))

              {

                  sum=x+1;
                  i=i+occ-1;

              }

  }

    cout<<sum<<endl;
}

}


#include <iostream>
#include<string>
#include <sstream>
#include<vector>
#include<bits/stdc++.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

int main ()
{
int n,t,sum,occ,x;
cin>>t;

while(t--)
{

    cin>>n;

    int a[n];

    for(int i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);

     sum=1;
  for(int i=0;i<n;i++)
  {

        occ=count(a, a + n, a[i]);

        x=occ+i-1;
      if(a[i]<=sum)
      {
        sum++;

      }

      else if((x)>=(a[i]))

              {

                  sum=x+1;
                  i=i+occ-1;

              }

              else
               i=i+occ-1;

  }

    cout<<sum<<endl;
}

}


#include <iostream>
#include<string>
#include <sstream>
#include<vector>
#include<bits/stdc++.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

int main ()
{
int n,t,sum,occ,c,x;
cin>>t;

while(t--)
{

    cin>>n;

    int a[n];

    for(int i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);
    c=0;
    sum=1;
  for(int i=0;i<n;i++)
  {

        occ=count(a, a + n, a[i])-1;

        x=occ+c+sum;

      if(a[i]<=sum)
      {
        sum++;
        c=0;
      }

      else if((x)>=(a[i]))

              {
                  sum=sum+occ+1+c;
                  i=i+occ+1;
              }
      else
        c++;

  }

    cout<<sum<<endl;
}

}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;
const int nax = 55;

int32_t main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <int> v(n);
        for (int i = 0; i < n ; i++) {
            cin >> v[i];
        }
        int last = 1;
        sort (v.begin(), v.end());
        if (v[0] > 1) {
            cout << 1 << endl;
            continue;
        }
        if (v[n - 1] < n) {
            cout << n + 1 << endl;
            continue;
        }
        for (int i = 0; i < n; i++) {
            if (i + 1 >= v[i]) {
                last = i;
            }
        }
        cout << last + 2 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;
const int nax = 55;

int32_t main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <int> v(n);
        for (int i = 0; i < n ; i++) {
            cin >> v[i];
        }
        int ans = 1;
        sort (v.begin(), v.end());
        if (v[0] > 1) {
            cout << 1 << endl;
            continue;
        } else if (v[n - 1] <= n) {
            cout << n + 1 << endl;
            continue;
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (cnt != 0 and ans + cnt >= v[i]) {
                ans += cnt;cnt = 0;
            }
            if (ans >= v[i]) ans++,cnt = 0  ;
            else {
                cnt++;
                continue;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;
const int nax = 55;

int32_t main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <int> v(n);
        for (int i = 0; i < n ; i++) {
            cin >> v[i];
        }
        int last = 1;
        sort (v.begin(), v.end());
        if (v[n - 1] < n) {
            cout << n + 1 << endl;
            continue;
        }
        for (int i = 0; i < n; i++) {
            if (i + 1 >= v[i]) {
                last = i;
            }
        }
        if (last == 0 or last == 1) {
            cout << 1 << endl;
            continue;
        }
        cout << last + 2 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;
const int nax = 55;

int32_t main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <int> v(n);
        for (int i = 0; i < n ; i++) {
            cin >> v[i];
        }
        int ans = 1;
        sort (v.begin(), v.end());
        if (v[0] > 1) {
            cout << 1 << endl;
            continue;
        } else if (v[n - 1] <= n) {
            cout << n + 1 << endl;
            continue;
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (ans >= v[i]) ans++,cnt = 0  ;
            else cnt++;
            if (cnt != 0 and ans + cnt > v[i]) {
                ans += cnt;cnt = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;
const int nax = 55;

int32_t main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <int> v(n);
        for (int i = 0; i < n ; i++) {
            cin >> v[i];
        }
        int last = 1;
        sort (v.begin(), v.end());
        if (v[n - 1] < n) {
            cout << n + 1 << endl;
            continue;
        }
        for (int i = 0; i < n; i++) {
            if (i + 1 >= v[i]) {
                last = i;
            }
        }
        if (last == 1) {
            cout << 1 << endl;
            continue;
        }
        cout << last + 2 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;
const int nax = 55;

int32_t main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> arr(n);
        for (int &el : arr)
            cin >> el;
        bool ok = true;
        sort(arr.begin(), arr.end());
        for (int i = n - 1; i >= 0; i--) {
            if (arr[i] <= i + 1) {
                cout << i + 2 << '\n';
                ok = false;
                break;
            }
        }
        if (ok)
            cout << 1 << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;
const int nax = 55;

int32_t main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <int> v(n);
        for (int i = 0; i < n ; i++) {
            cin >> v[i];
        }
        int ans = 1;
        sort (v.begin(), v.end());
        if (v[0] > 1) {
            cout << 1 << endl;
            continue;
        } else if (v[n - 1] <= n) {
            cout << n + 1 << endl;
            continue;
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (ans > v[i]) ans++,cnt = 0  ;
            else cnt++;
            if (cnt != 0 and ans + cnt > v[i]) {
                ans += cnt;cnt = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int func(vector<int> vect, int n)
{
    if(n==0)
        return 1;

	if(*vect.begin()<=n)
		return n+1;

	vect.erase(vect.begin());
	n--;
	return func(vect,n);

}

int main()
{
	int t,n,num,i;
	cin>>t;
	vector<int> arr;

	while(t--)
	{
		arr.clear();
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>num;
			arr.push_back(num);
		}

		sort(arr.begin(), arr.end(), greater<int>());

		cout<<func(arr,n)<<endl;

	}
	return 0;
}


#include<iostream>
#include <vector>
#include <algorithm>
using namespace std;

int func(vector<int> vect, int n)
{
    if(n==0)
        return 1;

	if(*vect.begin()<=n)
		return n+1;

	vect.erase(vect.begin());
	n--;
	return func(vect,n);

}

int main()
{
	int t,n,num,i;
	cin>>t;
	vector<int> arr;

	while(t--)
	{
		arr.clear();
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>num;
			arr.push_back(num);
		}

		sort(arr.begin(), arr.end(), greater<int>());

		cout<<func(arr,n)<<endl;

	}
	return 0;
}


#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;

int func(vector<int> vect, int n)
{
   for(auto itr=vect.begin(); itr<=vect.end() ;itr++)
   {
   		if(*itr<=n)
   			return n+1;
   		n--;
   }
   return n+2;

}

int main()
{
	int t,n,num,i;
	cin>>t;
	vector<int> arr;

	while(t--)
	{
		arr.clear();
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>num;
			arr.push_back(num);
		}

		sort(arr.begin(), arr.end(), greater<int>());

		cout<<func(arr,n)<<endl;

	}
	return 0;
}


#include<iostream>
#include <deque>
#include <algorithm>

using namespace std;

int func(deque<int> vect, int n)
{
    if(n==0)
        return 1;

	if(*vect.begin()<=n)
		return n+1;

	vect.erase(vect.begin());
	n--;
	return func(vect,n);

}

int main()
{
	int t,n,num,i;
	cin>>t;
	deque<int> arr;

	while(t--)
	{
		arr.clear();
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>num;
			arr.push_back(num);
		}

		sort(arr.begin(), arr.end(), greater<int>());

		cout<<func(arr,n)<<endl;

	}
	return 0;
}


#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;

int func(vector<int> vect, int n)
{
    if(n==0)
        return 1;

	if(*vect.begin()<=n)
		return n+1;

	vect.erase(vect.begin());
	n--;
	return func(vect,n);

}

int main()
{
	int t,n,num,i;
	cin>>t;
	vector<int> arr;

	while(t--)
	{
		arr.clear();
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>num;
			arr.push_back(num);
		}

		sort(arr.begin(), arr.end(), greater<int>());

		cout<<func(arr,n)<<endl;

	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void Flash(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll cnt,maxi=-1,mini;
ll m,k,n,x;
ll mini1=1e9,maxi1=-1,cnt1,cnt2,cnt3,ans,sum;
int main(){
	Flash();
	// freopen (" .txt", "r", stdin);
	// freopen (" .txt", "w", stdout);
	ll t;
	cin>>t;
	while(t--){
	    cin>>n;
	    int a[n];
	    for(int i=0; i<n; i++){
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    if(a[0]!=1){
	        cout<<1<<endl;
	        continue;
	    }
	    if(a[n-1]==1){
	        cout<<n+1<<endl;
	        continue;
	    }
	    cnt=1;
	    for(int i=0; i<n; i++){
	        if(a[i]==1){
	            cnt++;
	        }
	        else{
	            k=i;
	            break;
	        }
	    }
	    cnt1=cnt;
	    for(int i=k; i<n; i++){
	        if(cnt1>=a[i]){
	            cnt1++;
	            cnt=cnt1;
	            continue;
	        }
	        if(cnt1<a[i]){
	            cnt1++;
	        }
	        if(cnt1-1>=a[i]){
	            cnt=cnt1;
	        }
	    }
	    cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void Flash(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll cnt,maxi=-1,mini;
ll m,k,n,x;
ll mini1=1e9,maxi1=-1,cnt1,cnt2,cnt3,ans,sum;
int main(){
	Flash();
	// freopen (" .txt", "r", stdin);
	// freopen (" .txt", "w", stdout);
	ll t;
	cin>>t;
	while(t--){
	    cin>>n;
	    int a[n];
	    for(int i=0; i<n; i++){
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    if(a[n-1]==1){
	        cout<<n+1<<endl;
	        continue;
	    }
	    cnt=1;
	    for(int i=0; i<n; i++){
	        if(a[i]==1){
	            cnt++;
	        }
	        else{
	            k=i;
	            break;
	        }
	    }
	    cnt1=cnt;
	    for(int i=k; i<n; i++){
	        cnt1++;
	        if(cnt1-1>=a[i]){
	            cnt=cnt1;
	        }
	    }
	    cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void Flash(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll cnt,maxi=-1,mini;
ll m,k,n,x;
ll mini1=1e9,maxi1=-1,cnt1,cnt2,cnt3,ans,sum;
int main(){
	Flash();
	// freopen (" .txt", "r", stdin);
	// freopen (" .txt", "w", stdout);
	ll t;
	cin>>t;
	while(t--){
	    cin>>n;
	    int a[n];
	    for(int i=0; i<n; i++){
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    if(a[0]!=1){
	        cout<<1<<endl;
	        continue;
	    }
	    if(a[n-1]==1){
	        cout<<n+1<<endl;
	        continue;
	    }
	    cnt=1;
	    for(int i=0; i<n; i++){
	        if(a[i]==1){
	            cnt++;
	        }
	        else{
	            k=i;
	            break;
	        }
	    }
	    cnt1=cnt;
	    for(int i=k; i<n; i++){
	        if(cnt1>=a[i]){
	            cnt1++;
	            cnt=cnt1;
	            continue;
	        }
	        if(cnt1<a[i]){
	            cnt1++;
	        }
	    }
	    cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void Flash(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll cnt,maxi=-1,mini;
ll m,k,n,x;
ll mini1=1e9,maxi1=-1,cnt1,cnt2,cnt3,ans,sum;
int main(){
	Flash();
	// freopen (" .txt", "r", stdin);
	// freopen (" .txt", "w", stdout);
	ll t;
	cin>>t;
	while(t--){
	    cin>>n;
	    int a[n];
	    for(int i=0; i<n; i++){
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    if(a[0]!=1){
	        cout<<1<<endl;
	        continue;
	    }
	    if(a[n-1]==1){
	        cout<<n+1<<endl;
	        continue;
	    }
	    cnt=1;
	    for(int i=0; i<n; i++){
	        if(a[i]==1){
	            cnt++;
	        }
	        else{
	            k=i;
	            break;
	        }
	    }
	    cnt1=cnt;
	    for(int i=k; i<n; i++){
	        cnt1++;
	        if(cnt1-1>=a[i]){
	            cnt=cnt1;
	        }
	    }
	    cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void Flash(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll cnt,maxi=-1,mini;
ll m,k,n,x;
ll mini1=1e9,maxi1=-1,cnt1,cnt2,cnt3,ans,sum;
int main(){
	Flash();
	// freopen (" .txt", "r", stdin);
	// freopen (" .txt", "w", stdout);
	ll t;
	cin>>t;
	while(t--){
	    cin>>n;
	    int a[n];
	    for(int i=0; i<n; i++){
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    if(a[n-1]==1){
	        cout<<n+1<<endl;
	        continue;
	    }
	    cnt=1;
	    for(int i=0; i<n; i++){
	        if(a[i]==1){
	            cnt++;
	        }
	        else{
	            k=i;
	            break;
	        }
	    }
	    cnt1=cnt;
	    for(int i=k; i<n; i++){
	        if(cnt1>=a[i]){
	            cnt1++;
	            cnt=cnt1;
	            continue;
	        }
	        if(cnt1<a[i]){
	            cnt1++;
	        }
	    }
	    cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void Flash(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll cnt,maxi=-1,mini;
ll m,k,n,x;
ll mini1=1e9,maxi1=-1,cnt1,cnt2,cnt3,ans,sum;
int main(){
	Flash();
	// freopen (" .txt", "r", stdin);
	// freopen (" .txt", "w", stdout);
	ll t;
	cin>>t;
	while(t--){
	    cin>>n;
	    int a[n];
	    for(int i=0; i<n; i++){
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    cnt=1;
	    for(int i=0; i<n; i++){
	        if(a[i]==1){
	            cnt++;
	        }
	        else{
	            k=i;
	            break;
	        }
	    }
	    cnt1=cnt;
	    for(int i=k; i<n; i++){
	        cnt1++;
	        if(cnt1-1>=a[i]){
	            cnt=cnt1;
	        }
	    }
	    cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void Flash(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll cnt,maxi=-1,mini;
ll m,k,n,x;
ll mini1=1e9,maxi1=-1,cnt1,cnt2,cnt3,ans,sum;
int main(){
	Flash();
	// freopen (" .txt", "r", stdin);
	// freopen (" .txt", "w", stdout);
	ll t;
	cin>>t;
	while(t--){
	    cin>>n;
	    int a[n];
	    for(int i=0; i<n; i++){
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    if(a[0]!=1){
	        cout<<1<<endl;
	        continue;
	    }
	    cnt=1;
	    for(int i=0; i<n; i++){
	        if(a[i]==1){
	            cnt++;
	        }
	        else{
	            k=i;
	            break;
	        }
	    }
	    cnt1=cnt;
	    for(int i=k; i<n; i++){
	        cnt1++;
	        if(cnt1-1>=a[i]){
	            cnt=cnt1;
	        }
	    }
	    cout<<cnt<<endl;
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++)
cin>>a[i];
int count=1;
sort(a.begin(), a.end());
while(count>=a[count-1])
count++;
cout<<count;
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++)
cin>>a[i];
int count=1;
sort(a.begin(), a.end());
while(count+1>=a[count-1] && count<=n)
count++;
cout<<count<<endl;
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++)
cin>>a[i];
int count=1;
sort(a.begin(), a.end());
int max_count;
while(count<=n){
    if(count>=a[count-1])
        max_count=count;
    count++;
}
cout<<max_count<<endl;
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++)
cin>>a[i];
int count=1;
sort(a.begin(), a.end());
while(count>=a[count-1])
count++;
cout<<count<<endl;
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++)
cin>>a[i];
int count=1;
sort(a.begin(), a.end());
int max_count=0;
while(count<=n){
    if(count>=a[count-1])
        max_count=count;
    count++;
}
if(max_count==0)
cout<<1<<endl;
else
cout<<max_count+1<<endl;
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++)
cin>>a[i];
int count=1;
sort(a.begin(), a.end());
while(count>=a[count-1])
count++;
cout<<count;
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++)
cin>>a[i];
int count=1;
sort(a.begin(), a.end());
while(count>=a[count-1] && count<=n)
count++;
cout<<count<<endl;
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++)
cin>>a[i];
int count=1;
sort(a.begin(), a.end());
int max_count;
while(count<=n){
    if(count>=a[count-1])
        max_count=count;
    count++;
}
cout<<max_count+1<<endl;
}
return 0;
}


// NOT_SO_SACXY

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ll              long long
#define MAXN            100010
#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define repp(i, a, b)   for(int i = a; i <= b; i++)
#define rep(i, a, b)    for(int i = a; i < b; i++)
#define rrep(i, b, a)   for(int i = b; i >= a; i--)
#define all(v)          v.begin(),v.end()
#define rall(v)         v.rbegin(),v.rend()
#define lb              lower_bound
#define ub              upper_bound
#define endl            "\n"
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define loop(i,s,n)     for(ll i=s;i<n;i++)
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve(){
    int n;
        cin>>n;
        // cout << n << endl;
        int a[n];
        rep(i,0,n)cin>>a[i];
        set<int> s;
        unordered_map<int,int> m;
        rep(i,0,n)
        {
            s.insert(a[i]);
            m[a[i]]++;
        }
        int cnt=0,cur,nany=0;
        // cout << 1 << endl;
        for(int x : s)
        {
            nany+=m[x];
            if(cur+m[x] >= x)
            {
                cnt += nany;
                // cout << cnt << endl;
                nany = 0;
            }
            cur += m[x];
        }
        cout << cnt+1 << endl;

}

// void solve()
// {
//     ll n;   cin>>n;
//     ll a[n];    loop(i,0,n)     cin>>a[i];
//     set<ll> S;
//     unordered_map<ll,ll> M;
//     loop(i,0,n)
//     {
//         S.insert(a[i]);
//         M[a[i]]++;
//     }
//     ll cnt=0,cur,nany=0;
//     for(ll x : S)
//     {
//         nany+=M[x];
//         if(cur+M[x]>=x)
//         {

//             cnt+=nany;
//             // cout << cnt << endl;
//             nany=0;
//         }
//         cur+=M[x];
//     }
//     cout<<cnt+1<<endl;
// }

int32_t main()
{
    c_p_c();
    w(t){

        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	int t; cin>>t;
	while(t--)
	{
		int n; cin>>n;
		ll a[n];
		for(int i=0;i<n;i++) cin>>a[i];

		sort(a,a+n);
		ll ans=0;
		for(int i=n-1;i>=0;i--)
		{
			ans=i+1;
			if(ans>=a[i])
			break;
			else
			ans=0;
		}
		if(ans==0)
		cout<<1<<"\n";
		else
		cout<<ans+1<<"\n";

	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
int main()
{
int t = 0 ; cin >> t ; while(t--)
{
int n = 0;
cin >> n ;
vector<int> v (n);
map<int,int> m;
set<int> s;
for(int i = 0; i < n ; i++)
{
    cin >> v[i];
    m[v[i]]++;
    s.insert(v[i]);
}
vector<pair<int,int>>ans;
set <int> :: iterator itr;
int a = 0;
int b = 0;
for(itr = s.begin() ;  itr != s.end() ; itr++)
{
    a = *itr;
    b = m[*itr];
    ans.push_back(make_pair(a,b));
}
for(int i = 1; i < ans.size() ; i++)
{
  ans[i].second = ans[i].second + ans[i-1].second;
}
int answer = 1;
int maximum = 0;
for(int i = 0 ; i < n ; i++)
{
if(ans[i].second >= ans[i].first)
{
maximum = max(ans[i].second , maximum);
}
}
answer = answer + maximum;
cout << answer << endl;
}
return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
signed main()
{
int t = 0 ; cin >> t ; while(t--)
{
int n = 0;
cin >> n ;
vector<int> v (n);
map<int,int> m;
set<int> s;
for(int i = 0; i < n ; i++)
{
    cin >> v[i];
    m[v[i]]++;
    s.insert(v[i]);
}
vector<pair<int,int>>ans;
set <int> :: iterator itr;
int a = 0;
int b = 0;
for(itr = s.begin() ;  itr != s.end() ; itr++)
{
    a = *itr;
    b = m[*itr];
    ans.push_back(make_pair(a,b));
}
for(int i = 1; i < ans.size() ; i++)
{
  ans[i].second = ans[i].second + ans[i-1].second;
}
int answer = 1;
int maximum = 0;
for(int i = 0 ; i < n ; i++)
{
if(ans[i].second >= ans[i].first)
{
maximum = max(ans[i].second , maximum);
}
}
answer = answer + maximum;
cout << answer << endl;
}
return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> v;int j;
        for(int i=0;i<n;i++)
        {
            cin>>j;
            v.push_back(j);
        }
        sort(v.begin(),v.end());
        int count=1;int k=1;
        //cout<<v[n-k]<<endl;
        while(v[n-k]>n-k + 1)
        {
        	k++;
        	//cout<<k<<endl;
        }

        cout<<(n-k+1) + 1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define tc int tc; cin>>tc; while(tc--)
using namespace std;

int main() {
    int t;
    cin >> t;

    while(t--){
        ll n;
        cin>>n;
        ll i,a[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        ll ans=1,temp=1;
        if(a[0]>1)
        {
            cout<<ans<<endl;
        }else{
            ans++;
            temp=ans;
            for(i=1;i<n;i++)
            {
                if(a[i]<=ans)
                {
                    ans++;
                    temp=ans;
                }else{
                    temp++;
                    for(ll j=i+1;j<n;j++)
                    {
                        if(temp-a[j]==0)
                        {
                            i=j;
                            ans=temp+1;
                            break;
                        }
                        temp++;
                    }
                }
            }
            cout<<ans<<endl;
        }

    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int t = 0 ; cin >> t ; while(t--)
{
int n = 0;
cin >> n ;
vector<int> v (n);
map<int,int> m;
set<int> s;
for(int i = 0; i < n ; i++)
{
    cin >> v[i];
    m[v[i]]++;
    s.insert(v[i]);
}
vector<pair<int,int>>ans;
set <int> :: iterator itr;
int a = 0;
int b = 0;
for(itr = s.begin() ;  itr != s.end() ; itr++)
{
    a = *itr;
    b = m[*itr];
    ans.push_back(make_pair(a,b));
}
for(int i = 1; i < ans.size() ; i++)
{
  ans[i].second = ans[i].second + ans[i-1].second;
}
int answer = 1;
int maximum = 0;
for(int i = 0 ; i < n ; i++)
{
if(ans[i].second >= ans[i].first)
{
maximum = max(ans[i].second , maximum);
}
}
answer = answer + maximum;
cout << answer << endl;
}
return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e5 +7;

void check(){
	int n;
	cin >> n;
	int a[MAXN] = {0};

	for(int i = 1 ;i <= n ;i++) cin >>a[i];
	sort(a+1 ,a+n+1);

	int ans = 0;

	for(int i = 1 ; i <= n ;i++){
		if(a[i] <= i)ans = max(ans ,i);
	}

	cout << ans <<'\n';
}

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e5 +7;

void check(){
	int n;
	cin >> n;
	int a[MAXN] = {0};

	for(int i = 1 ;i <= n ;i++) cin >>a[i];
	sort(a+1 ,a+n+1);

	int ans = 0;

	for(int i = 1 ; i <= n ;i++){
		if(a[i] <= i)ans = max(ans ,i);
	}

	cout << ans <<'\n';
}

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e5 +7;

void check(){
	int n;
	cin >> n;
	int a[MAXN] = {0};

	for(int i = 1 ;i <= n ;i++) cin >>a[i];
	sort(a+1 ,a+n+1);

	int ans = 0;

	for(int i = 1 ; i <= n ;i++){
		if(a[i] <= i)ans = max(ans ,i);
	}

	cout << ++ans <<'\n';
}

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e5 +7;

void check(){
	int n;
	cin >> n;
	int a[MAXN] = {0};
	for(int i = 0 ; i < n ;i++) cin >> a[i];
	sort(a ,a+n);

	for(int i = 0 ; i < n ;i++){
	    int cnt = 1 ,j = i+1;
	    while(j < n && a[j] == a[i])cnt++ ,a[j]-- ,j++;
	    if(cnt > 1)a[i]--;
	   // cout << MP(i ,j);
	    i = j-1;
	   // for(int k = 0 ;k <n ;k++) cout << a[k]<<" \n"[k == n-1];
	}

	int ans = 1;
    // for(int i = 0 ;i <n ;i++) cout << a[i]<<" \n"[i == n-1];
	for(int i = 0 ;i <n ;i++){
		ll mn = a[i] ,cnt = 0;
		while(i < n && a[i] == a[i+1])i++ ,cnt++;
		mn -= cnt;
		if(mn <= ans) ans += cnt+1;
	}
	cout << ans<<'\n';
}

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 1e5 +7;

void check(){
	int n;
	cin >> n;
	int a[MAXN] = {0};

	for(int i = 1 ;i <= n ;i++) cin >>a[i];
	sort(a+1 ,a+n+1);

	int ans = 0;

	for(int i = 1 ; i <= n ;i++){
		if(a[i] <= i)ans = max(ans ,i);
	}

	cout << ++ans <<'\n';
}

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    /*
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("-O3")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    */

    #define mp make_pair
    #define ll long long
    #define ld long double
    #define pb push_back
    #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define fs first
    #define sc second
    #define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
    #define endl '\n'
    #define pii pair<int, int>

    const int INF = 2000000005;
    const ll BIG_INF = 2000000000000000005;
    const int mod = 1000000007;
    const int P = 31;
    const ld PI = 3.141592653589793238462643;
    const double eps = 1e-9;

    using namespace std;
    using namespace __gnu_pbds;

    bool valid(int x, int y, int n, int m) {
        return x >= 0 && y >= 0 && x < n && y < m;
    }

    mt19937 rng(1999999973);

    typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

    signed main() {
        fast_io;

        int t;
        cin >> t;
        while(t--) {
            int n, ans = 1, curad = 0;
            cin >> n;
            vector<int> a(n);
            for (int i = 0; i < n; i++)
                cin >> a[i];
            sort(a.begin(), a.end());
            for (int i = 0; i < n; i++) {
                curad++;
                if (curad + ans > a[i]) {
                    ans += curad;
                    curad = 0;
                }
            }
            cout << ans << endl;
        }

        return 0;
    }


#include <bits/stdc++.h>

using namespace std;

int main() {
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		int a[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		bool ok = 0, ans = -1;
		for (int i = 0; i < n; i++) {
			if(a[i] <= i + 2) {
				ans = max(ans, i + 2);
			}
		}
		if (ans == -1) {
			cout << 1 << endl;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		int a[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		bool ok = 0;
		for (int i = 0; i < n; i++) {
			if(a[i] > i + 2 && ok == 0) {
				ok = 1;
				cout << i + 2 << endl;
				break;
			}
		}
		if (ok == false) {
			cout << 1 << endl;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		int a[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		bool ok = 0;
		for (int i = 0; i < n; i++) {
			if(a[i] <= i + 1 && ok == 0) {
				ok = 1;
				cout << i + 2 << endl;
				break;
			}
		}
		if (ok == false) {
			cout << 1 << endl;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		int a[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		long long ans = -1;
		for (long long i = 0; i < n; i++) {
			if(a[i] <= i + 2) {
				ans = max(ans, i + 2);
			}
		}
		if (ans == -1) {
			cout << 1 << endl;
		} else {
		    cout << ans + 1;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		int a[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		long long ans = -1;
		for (long long i = 0; i < n; i++) {
			if(a[i] <= i + 2) {
				ans = max(ans, i + 2);
			}
		}
		if (ans == -1) {
			cout << 1 << endl;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		int a[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		bool ok = 0;
		for (int i = 0; i < n; i++) {
			if(a[i] <= i + 2 && ok == 0) {
				ok = 1;
				cout << i + 2 << endl;
				break;
			}
		}
		if (ok == false) {
			cout << 1 << endl;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		int a[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		long long ans = -1;
		for (long long i = 0; i < n; i++) {
			if(a[i] <= i + 2) {
				ans = max(ans, i + 2);
			}
		}
		if (ans == -1) {
			cout << 1 << endl;
		} else {
		    cout << ans;
		}
	}
}


/*************************
* Author : Rakshit Meshram
* 645B
*************************/
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<=n;i++)

int main(){

	int t,n;
	cin >> t;
	while(t--){
		cin >> n;
		vector<int>d(n);
		rep(i,n){ cin >> d[i];}
		sort(d.begin(),d.end());
		int last = 0;
		REP(i,1,n){
			if(d[i-1]<=i)
				last = max(i,last);
		}
		cout << last + 1 << endl;

	}
	return 0;
}


/*************************
* Author : Rakshit Meshram
*************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<=n;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int) (x).size())
#define F first
#define S second

int main(){
	freopen("inputf.in","r",stdin);
	freopen("outputf.in","w",stdout);
	int t,n;
	cin >> t;
	while(t--){
		cin >> n;
		vector<int>d(n);
		rep(i,n){ cin >> d[i];}
		sort(d.begin(),d.end());
		int last = 0;
		REP(i,1,n){
			if(d[i-1]<=i)
				last = max(i,last);
		}
		cout << last + 1 << endl;

	}
	return 0;
}


/*************************
* Author : Rakshit Meshram
*************************/
#include<bits/stdc++.h>
using namespace std;

int main(){
	int t,n;
	cin >> t;
	while(t--){
		cin >> n;
		vector<int>d(n);
		rep(i,n){ cin >> d[i];}
		sort(d.begin(),d.end());
		int last = 0;
		REP(i,1,n){
			if(d[i-1]<=i)
				last = max(i,last);
		}
		cout << last + 1 << endl;

	}
	return 0;
}


/*************************
* Author : Rakshit Meshram
*************************/
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<=n;i++)

int main(){

	int t,n;
	cin >> t;
	while(t--){
		cin >> n;
		vector<int>d(n);
		rep(i,n){ cin >> d[i];}
		sort(d.begin(),d.end());
		int last = 0;
		REP(i,1,n){
			if(d[i-1]<=i)
				last = max(i,last);
		}
		cout << last + 1 << endl;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define nloop(i,a,n) for(ll i=(n-1);i>=a;i--)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define fastio     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define alla(a,n) a, a + n
#define debug(x) cout<<#x<<' '<<x<<endl;
#define fst first
#define snd second
#define test() ll t;  cin>>t; cin.ignore(); while(t--)
#define INF LLONG_MAX
#define SUP -1000000001
#define arrinp(x,n,arr) loop(i,x,n){cin>>arr[i];}
#define arrout(x,n,arr) loop(i,x,n){cout<<arr[i]<<" ";}cout<<endl;
#define aout(x) for(auto a: x){cout<<a<<" ";}cout<<endl;
#define out(x) cout<<x<<endl;
#define inp(x) ll x;cin>>x;
#define line cout<<endl;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main() {

        fastio

        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin) ;
        freopen("output.txt", "w", stdout) ;
        #endif

        // DO NOT USE VAR t,a;

        test()
        {
                inp(n);

                ll arr[n];

                arrinp(0,n,arr);

                ll h[200001]={0};

                loop(i,0,n)
                {
                        h[arr[i]]++;
                }
                loop(i,1,n)
                {
                        h[i]+=h[i-1];
                }

                ll sum=0;

                loop(i,0,*max_element(arr,arr+n)+1)
                {
                        if(h[i]>=i)
                        sum = h[i];
                }

                cout<<sum+1<<endl;
        }
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int &el : arr)
        cin >> el;
    sort(arr.begin(), arr.end());
    for (int i = n - 1; i >= 0; i--) {
        if (arr[i] <= i + 1) {
            cout << i + 2 << '\n';
            return;
        }
    }
    cout << 1 << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define nloop(i,a,n) for(ll i=(n-1);i>=a;i--)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define fastio     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define alla(a,n) a, a + n
#define debug(x) cout<<#x<<' '<<x<<endl;
#define fst first
#define snd second
#define test() ll t;  cin>>t; cin.ignore(); while(t--)
#define INF LLONG_MAX
#define SUP -1000000001
#define arrinp(x,n,arr) loop(i,x,n){cin>>arr[i];}
#define arrout(x,n,arr) loop(i,x,n){cout<<arr[i]<<" ";}cout<<endl;
#define aout(x) for(auto a: x){cout<<a<<" ";}cout<<endl;
#define out(x) cout<<x<<endl;
#define inp(x) ll x;cin>>x;
#define line cout<<endl;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main() {

        fastio

        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin) ;
        freopen("output.txt", "w", stdout) ;
        #endif

        // DO NOT USE VAR t,a;

        test()
        {
                inp(n);

                ll arr[n];

                arrinp(0,n,arr);

                ll h[200001]={0};

                loop(i,0,n)
                {
                        h[arr[i]]++;
                }
                loop(i,1,n)
                {
                        h[i]+=h[i-1];
                }

                ll sum=1;

                loop(i,0,*max_element(arr,arr+n)+1)
                {
                        if(h[i]>i)
                        sum = h[i];
                }

                cout<<sum<<endl;
        }
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define nloop(i,a,n) for(ll i=(n-1);i>=a;i--)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define fastio     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define alla(a,n) a, a + n
#define debug(x) cout<<#x<<' '<<x<<endl;
#define fst first
#define snd second
#define test() ll t;  cin>>t; cin.ignore(); while(t--)
#define INF LLONG_MAX
#define SUP -1000000001
#define arrinp(x,n,arr) loop(i,x,n){cin>>arr[i];}
#define arrout(x,n,arr) loop(i,x,n){cout<<arr[i]<<" ";}cout<<endl;
#define aout(x) for(auto a: x){cout<<a<<" ";}cout<<endl;
#define out(x) cout<<x<<endl;
#define inp(x) ll x;cin>>x;
#define line cout<<endl;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main() {

        fastio

        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin) ;
        freopen("output.txt", "w", stdout) ;
        #endif

        // DO NOT USE VAR t,a;

        test()
        {
                inp(n);

                ll arr[n];

                arrinp(0,n,arr);

                ll h[200001]={0};

                loop(i,0,n)
                {
                        h[arr[i]]++;
                }

                ll sum=1,ans=1,temp=0;

                loop(i,0,*max_element(arr,arr+n)+1)
                {
                        if((sum+h[i])>i)
                        {
                                sum+=h[i];
                        }
                        else
                        {
                                temp=0;
                                while(i<=*max_element(arr,arr+n))
                                {
                                        temp+=h[i];
                                        // debug(temp);
                                        // debug(i);
                                        if((temp+sum)>i)
                                        {
                                                break;
                                        }
                                        else
                                        {
                                                i++;
                                        }

                                }
                                if(i<=*max_element(arr,arr+n))
                                {
                                        sum+=temp;
                                }
                                // debug(sum);
                                // debug(i);
                        }
                }

                cout<<sum<<endl;

        }
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define nloop(i,a,n) for(ll i=(n-1);i>=a;i--)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define fastio     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define alla(a,n) a, a + n
#define debug(x) cout<<#x<<' '<<x<<endl;
#define fst first
#define snd second
#define test() ll t;  cin>>t; while(t--)
#define INF LLONG_MAX
#define SUP -1000000001
#define arrinp(x,n,arr) loop(i,x,n){cin>>arr[i];}
#define arrout(x,n,arr) loop(i,x,n){cout<<arr[i]<<" ";}cout<<endl;
#define aout(x) for(auto a: x){cout<<a<<" ";}cout<<endl;
#define out(x) cout<<x<<endl;
#define inp(x) ll x;cin>>x;
#define line cout<<endl;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

// DO NOT USE VAR t,a;
void addEdge(vector <pair<ll, ll> > adj[], ll u,
                                     ll v, ll wt)
{
    adj[u].push_back(make_pair(v, wt));
    adj[v].push_back(make_pair(u, wt));
}
void printGraph(vector<pair<ll,ll> > adj[], ll V)
{
    ll v, w;
    for (ll u = 0; u < V; u++)
    {
        cout << "Node " << u << " makes an edge with \n";
        for (auto it = adj[u].begin(); it!=adj[u].end(); it++)
        {
            v = it->first;
            w = it->second;
            cout << "\tNode " << v << " with edge weight ="
                 << w << "\n";
        }
        cout << "\n";
    }
}
void addEdge(vector<ll> adj[], ll u, ll v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}

// A utility function to do DFS of graph
// recursively from a given vertex u.
void DFSUtil(ll u, vector<ll> adj[],
                    vector<bool> &visited)
{
    visited[u] = true;
    cout << u << " ";
    for (ll i=0; i<adj[u].size(); i++)
        if (visited[adj[u][i]] == false)
            DFSUtil(adj[u][i], adj, visited);
}

// This function does DFSUtil() for all
// unvisited vertices.
void DFS(vector<ll> adj[], ll V)
{
    vector<bool> visited(V, false);
    for (ll u=0; u<V; u++)
        if (visited[u] == false)
            DFSUtil(u, adj, visited);
}

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
ll check(ll n)
{
    if(n <= 1)
    return 0;
    double q = 24*n+1;
    q = sqrt(q);
    q--;
    q = q/6;
    //debug(q);
    ll z = q;
    //debug(z);
    return z;
}
int32_t main() {

        fastio

        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin) ;
        freopen("output.txt", "w", stdout) ;
        #endif

        test()
        {
            inp(n)
            ll arr[n];
            ll hash[200005]={0};
            hash[0] = 1;
            ll max=-1;
            loop(i,0,n)
            {
                cin>>arr[i];
                hash[arr[i]]++;
                if(arr[i]>max)
                max = arr[i];
            }
            ll pre[200005] ={0};
            pre[0] = 1;
            loop(i,1,max+1)
            {
                pre[i] = pre[i-1] + hash[i];
            }
            ll temp=0;
            for(ll i=max;i>=1;i--)
            {
                if(pre[i]-1>=i)
                {cout<<pre[i]<<endl;
                temp++;
                break;}
            }
            if(!temp)
            cout<<1<<endl;

        }
}