#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;

int main() {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		int a[n + 5] = {0};
		int cnt[n + 5] = {0};
		int ans = 0;

		for(int i = 1; i <= n; i++) {
			cin >> cnt[i];

			int flag = 0;
			for(int j = 1; j <= cnt[i]; j++) {
				int v;
				cin >> v;
				if(a[v] == 0 && flag == 0) {
					a[v] = 1;
					flag = 1;
				}
			}
			if(flag == 0) {
				ans = i;
			}
		}

		if(ans == 0) {
			cout << "OPTIMAL" << endl;
		} else {
			cout << "IMPROVE" << endl;
			for(int j = 1; j <= n; j++) {
				if(a[j] == 0) {
					cout << ans << ' ' << j << endl;
					break;
				}
			}
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int k[n+5];
		int b[n+5]={0};
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			cin>>k[i];
			int fla=0;
			for(int j=1;j<=k[i];j++)
			{
				int x;
				cin>>x;
				if(b[x]==0&&fla==0)//尝试匹配
				{
					b[x]++;//匹配过的就记录下来
					fla=1;
				}
			}
			if(fla==0)
			ans=i;//记录到底可不可以
		}
		if(!ans)
		{
			cout<<"OPTIMAL \n";
			continue;
		}
		cout<<"IMPROVE \n";
		for(int i=1;i<=n;i++)
		{
			if(b[i]==0)
			{
				cout<<ans<<" "<<i<<endl;
				break;
			}
		}//枚举每个人是否没有匹配
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int T;
int n,x,t,ans,ans2;
bool vis[100005];
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		ans=0;
		ans2=0;
		scanf("%d",&n);
		for (int i=1;i<=n;i++)
		{
			scanf("%d",&x);
			bool flag=0;
			for (int j=1;j<=x;j++)
			{
				scanf("%d",&t);
				if (vis[t]==0&&flag==0)
				{
					vis[t]=1;
					flag=1;
				}
			}
			if (!flag)
				ans=i;
		}
		for (int i=1;i<=n;i++)
		{
			if (vis[i]==0)
			{
				ans2=i;
			}
			vis[i]=0;
		}
		if (ans&&ans2)
			printf("IMPROVE\n%d %d\n",ans,ans2);
		else
			printf("OPTIMAL\n");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod1=1e9+7;
const ll mod2=0x3f3f3f3f;
const ll maxn=2e5+5;
const double eps=1e-6;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
    	int n,k,q;
    	scanf("%d",&n);
    	int vis[maxn]={0};
    	int a=0,b=0;
    	for(int i=1;i<=n;i++){
         scanf("%d",&k);
         a=0;
         while(k--){
         	 scanf("%d",&q);
         	 if(!vis[q]&&!a){
                  a=q;
         	 }
         }
         if(a)  vis[a]=1;
         else   b=i;
    	}
    	if(!b) printf("OPTIMAL\n");
    	else{
    		int ans=0;
    		for(int i=1;i<=n;i++){
    			if(!vis[i]){
    				ans=i;
    				break;
    			}
    		}
    		printf("IMPROVE\n");
    		printf("%d %d\n",b,ans);
    	}

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod1=1e9+7;
const ll mod2=0x3f3f3f3f;
const ll maxn=1e5+5;
const double eps=1e-6;
int main(){
    int t,n,k,q;
    scanf("%d",&t);
    while(t--){
    	scanf("%d",&n);
    	int vis[maxn]={0};
    	int a=0,b=0;
    	for(int i=1;i<=n;i++){
    	 a=0;
         scanf("%d",&k);
         while(k--){
         	 scanf("%d",&q);
         	 if(!vis[q]&&!a)  a=q;
         }
         if(a)  vis[a]=1;
         else   b=i;
    	}
    	if(!b) puts("OPTIMAL");
    	else{
    		puts("IMPROVE");
    		int ans=0;
    		for(int i=1;i<=n;i++){
    			if(!vis[i]){
    				ans=i;
    				break;
    			}
    		}
    		printf("%d %d\n",b,ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod1=1e9+7;
const ll mod2=0x3f3f3f3f;
const ll maxn=2e5+5;
const double eps=1e-6;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
    	int n,k,q;
    	scanf("%d",&n);
    	int vis[maxn]={0};
    	int a=0,b=0;
    	for(int i=1;i<=n;i++){
         scanf("%d",&k);
         a=0;
         while(k--){
         	 scanf("%d",&q);
         	 if(!vis[q]&&!a){
                  a=q;
         	 }
         }
         if(a)  vis[a]=1;
         else   b=i;
    	}
    	if(!b) printf("OPTIMAL\n");
    	else{
    		printf("IMPROVE\n");
    		int ans=0;
    		for(int i=1;i<=n;i++){
    			if(!vis[i]){
    				ans=i;
    				break;
    			}
    		}
    		printf("%d %d\n",b,ans);
    	}

    }

    return 0;
}


#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<queue>
#include <stack>
#include <bits/stdc++.h>
using namespace std;

#define F(i,b,n)  for(int i=(b);i<(n);i++)
#define f(i,b,n)  for(int i=(b);i<=(n);i++)
#define ll long long

const char* turns="FLR";
const char* dires="ESWN";
const int maxn=110;

int dx[]={1,0,-1,0};//传统的坐标系变换
int dy[]={0,-1,0,1};

int dr[]={1,0,-1,0};//行列变化
int dc[]={0,-1,0,1};
int mex1=0,mex2=0;
int s[maxn];

int main()
{
	int T;
	scanf ("%d",&T);
	while (T--)
	{
		memset(s,0,sizeof(s));
		int ans=0,flag=0;
		int n;
		scanf ("%d",&n);
		F(i,0,n)
		{
			int num;
			scanf ("%d",&num);
			s[num]++;
		}
		for (int i=0;flag!=2;i++)
		{
			if (s[i]==0)
			{
				if (flag==0) flag=2,ans=ans+i*2;
				else if(flag==1) flag=2,ans+=i;
			}
			else if (s[i]==1 && flag==0) flag++,ans+=i;
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=2e5+9;
ll len,vis[N],x;
void find()
{
    cin>>len;
    memset(vis,0,sizeof(vis));
    ll mx=0;
    for(int i=1; i<=len; i++)
	{
        cin>>x;
        vis[x]++;
        if(x>mx)mx=x;
    }
    int ans=0;
    for(int i=0; i<=mx+1;i++)
    if(vis[i]==0)
	{
	ans+=i;
	break;
	}
    for(int i=0; i<=mx+1; i++)
    if(vis[i]<=1)
	{
	ans+=i;break;
	}
	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(0);
    ll T;
    cin>>T;
    while(T--)
	{
		find();
		//cout<<ans<<endl;
	}
}


#include <iostream>
#include <algorithm>
int a[1024], b[1024];
bool aopy[1024];
int maxmex = 0;
int n, nb;

int main() {
	int t = 0;
	for (std::cin >> t; t > 0; t--) {
		int mexa = 0;
		int mexb = 0;
		for (int i = 0; i <= 255; i++) {
			a[i] = 0;
			b[i] = 0;
			aopy[i] = false;
		}
		std::cin >> n;
		nb = n;
		for (int i = 1; i <= n; i++)
			std::cin >> a[i];
		std::sort(a + 1, a + 1 + n);
		a[n + 1] = -1;
		for (int i = 1; i <= n; i++) {
			if (a[i] > mexa) {
				break;
			}
			else {
				if (a[i] != a[i + 1]) {
					aopy[i] = true;
					nb--;
					mexa++;
				}
			}
		}
		int k = 0;
		for (int j = 1; j <= n; j++) {
			if (aopy[j])continue;
			else {
				k++;
				b[k] = a[k];
			}
		}
		b[k + 1] = -1;
		for (int m = 1; m <= nb; m++) {
			if (b[m] > mexb)
				break;
			else
				if (b[m] != b[m + 1])
					mexb++;
		}
		maxmex = mexa + mexb;
		std::cout << maxmex << std::endl;
	}
	return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
const int INF=0x3f3f3f3f;
int read()
{
   int s=0,bj=0;
   char ch=getchar();
   while(ch<'0'||ch>'9')bj|=(ch=='-'),ch=getchar();
   while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
   return bj?-s:s;
}
void printnum(int x)
{
	if(x>9)printnum(x/10);
	putchar(x%10^48);
}
void print(int x,char ch)
{
	if(x<0){putchar('-');x=-x;}
	printnum(x);putchar(ch);
}
int T,n;
int a[105];
int vst1[105],vst2[105];
int main()
{
	T=read();
	while(T--)
	{
		n=read();int bj1=0,bj2=0,ans=0;
		for(int i=1;i<=n;++i)a[i]=read();
		sort(a+1,a+n+1);memset(vst1,0,sizeof(vst1));memset(vst2,0,sizeof(vst2));
		for(int i=1;i<=n;++i)
		{
			if(!vst1[a[i]])vst1[a[i]]=1;
			else if(!vst2[a[i]])vst2[a[i]]=1;
		}
		for(int i=0;i<=100;++i)
		{
			if(!vst1[i]&&!bj1){ans+=i;bj1=1;}
			if(!vst2[i]&&!bj2){ans+=i;bj2=1;}
		}
		print(ans,'\n');
	}
	return 0;
}


#include <bits/stdc++.h>
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
#define ppt(x) __builtin_popcount(x)
using namespace std;

const int INF=0x3f3f3f3f,N=2e5+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
template<typename T>
inline int getplc(T x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
  LL res=1;
  for(;b;b>>=1,a=a*a%_MOD){
    if(b&1)res=res*a%_MOD;
  }
  return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  errl(++it, args...);
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << " # ";
  err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
//  freopen("o1.txt","w",stdout);
#endif
  ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
  Solve();
  return 0;
}

////////////////////////////////////////////////////////////////////////

int cnt[N];
void Solve()
{
  int cas;
  for(cin>>cas;cas--;){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
      int x;
      cin>>x;
      cnt[x]++;
    }
    int ans=0,t=2;
    for(int i=0;i<=n;i++){
      if(cnt[i]<t)ans+=i,t--;
    }
    cout<<ans<<'\n';

    for(int i=0;i<=100;i++)cnt[i]=0;
  }
}


/*
@ author:pyyyyyy
-----思路------
对于本题而言，最优秀的无非就是两个连续的集合
对于不连续的集合来说，大的是没用的，所以要把数从小到大连续分
如果一旦出现不连续的情况，那么答案必定是最先出现的两个不连续数之和
如果这个做，比较复杂，需要特盘一些情况
本题一共没多少数，所以可以直接枚举
-----debug-------

*/

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

inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

const int N = 100001;
int t, n, a[N], vis[N];

int dfs(){
	int ret = 0;
	for(int j = 0; j <= 100; ++j){
		for(int i = 1; i <= 100; ++i){
			if(a[i] == j && !vis[i]){
				vis[i] = 1;
				ret++;
				break;
			}
//			if(a[i] > j) return ret;
//			if(i == n) return ret;
		}
	}
	return ret;
}

int main()
{
	//	freopen(".in","r",stdin);
	//	freopen(".out","w",stdout);
	t = read();
	while(t--){
		int ans = 0;
		memset(vis, 0, sizeof(vis));
		n = read();
		for(int i = 1; i <= n; ++i) a[i] = read();
		sort(a + 1, a + 1 + n);
		ans += dfs();
		ans += dfs();
		cout << ans << '\n';
	}
	return 0;
}
/*
input：

output:

*/


#include<bits/stdc++.h>
using namespace std;
int t,n;
int a[1000],maxx;
int main(){
	cin>>t;
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			int x;
			scanf("%d",&x);
			maxx=max(maxx,x);
			a[x]++;
		}
		int flag1=-1,flag2=-1;
		int m2;
		for(int i=0;i<=maxx;i++){
			if(flag1!=-1&&flag2!=-1) break;
			if(a[i]<2){
				if(a[i]==0){
					if(flag1==-1) flag1=i;
					if(flag2==-1) flag2=i;
				}
				if(a[i]==1){
					if(flag1==-1){
						flag1=i;
						m2=i;
					}
					else if(i!=m2+1&&flag2==-1){
						flag2=i;
					}
                    else m2=i;
				}
			}
			else m2=i;
		}
		cout<<flag1+flag2<<endl;
		memset(a,0,sizeof(a));
	}
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,b,a) for ( int i=(b);i>=(a);i-- )
#define GO(i,x) for ( int i=head[x];i;i=e[i].nex )
#define mem(x,s) memset(x,s,sizeof(x))
#define cpy(x,s) memcpy(x,s,sizeof(x))
#define YES return puts("YES"),0
#define NO return puts("NO"),0
#define GG return puts("-1"),0
#define pb push_back
using namespace std;

struct IO
{
	#define MAXSIZE (1 << 20)
	#define isdigit(x) (x >= '0' && x <= '9')
  	char buf[MAXSIZE],*p1,*p2;
  	char pbuf[MAXSIZE],*pp;
  	IO():p1(buf),p2(buf),pp(pbuf){}
  	inline char gc() {
    	return getchar();
    	if (p1==p2) p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin);
    	return p1==p2?' ':*p1++;
  	}
	inline bool blank(char ch) {return ch==' '||ch =='\n'||ch == '\r'||ch == '\t';}
  	template <class T>
  	inline void read(T &x)
	{
	    register double tmp=1;register bool sign=0; x=0;
	    register char ch=gc();
	    for (;!isdigit(ch);ch=gc()) if(ch=='-') sign=1;
	    for (;isdigit(ch);ch=gc()) x=x*10+(ch-'0');
	    if (ch=='.') for (ch=gc();isdigit(ch);ch=gc()) tmp/=10.0,x+=tmp*(ch-'0');
	    if (sign) x=-x;
  	}
  	inline void read(char *s)
	{
    	register char ch=gc();
		for (;blank(ch);ch=gc());
		for (;!blank(ch);ch=gc()) *s++=ch;
    	*s=0;
  	}
  	inline void read(char &c) {for(c=gc();blank(c);c=gc());}
  	template<class t> inline void write(t x){
		if(x<0) putchar('-'),write(-x);
		else{if(x>9) write(x/10);putchar('0'+x%10);}
	}
} io;

const int mod=1e9+7;
const int mo=998244353;
const int N=2e5+5;

int n,m,a[105],ls[105],ans,Q,mx;

int main()
{
	io.read(Q);
	for (;Q--;)
	{
		io.read(n),mx=0;
		For(i,0,101) ls[i]=0;
		For(i,1,n) io.read(a[i]),ls[a[i]]++;

		ans=0;
		For(i,0,101) if(!ls[i])
		{
			ans+=i;
			break;
		}
		For(i,0,101) if(ls[i]<=1)
		{
			ans+=i;
			break;
		}
		io.write(ans),puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,n,a[105],f[105];
int main(){
    cin>>t;
    for(int i(0);i<t;++i){
    	cin>>n;
    	memset(a,0,sizeof(a));
    	memset(f,0,sizeof(f));
    	for(int j(0);j<n;++j){
    		cin>>a[j];
    		f[a[j]]++;
		}sort(a,a+n);int ans=0,num=0;
		for(int j(0);j<n;++j){
			if(a[j]==num&&f[a[j]]>0){
				num++;
				ans++;
				f[a[j]]--;
			}else{
				if(a[j]>num)break;
			}
		}num=0;
		for(int j(0);j<n;++j){
			if(a[j]==num&&f[a[j]]>0){
				num++;
				ans++;
				f[a[j]]--;
			}else{
				if(a[j]>num)break;
			}
		}cout<<ans<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

const int N = 1e3 + 5;

int a[N], n, m, res = 0;

int main()
{
    int t;
    ios::sync_with_stdio(false);
    cin >> t;
    while (t -- )
    {
        cin >> n;
        memset(a, 0, sizeof(a));
        for (int i = 1; i <= n; i ++ )
        {
            int k;
            cin >> k;
            a[k] ++;
        }
        int aa = 0, bb = 0;
        for (int i = 0; a[i] > 0; i ++ )
        {
            aa ++;
            a[i] -= 1;
        }
        for (int i = 0; a[i] > 0; i ++ )
        {
            bb ++;
            a[i] -= 1;
        }
        cout << aa + bb << endl;

    }
    return 0;
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        int i=0, ans=0;
        while(cnt[i]>=2){
            i++;
            if(cnt[i]>=2){
                continue;
            }
            if(cnt[i]==0){
                ans = i*2;
                break;
            }
            ans = i;
        }
        while(cnt[i]==1){
            i++;
            if(cnt[i]==1){
                continue;
            }
            ans += i;
        }
        cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        // rep(i,0,101){
        //     cout<<cnt[i]<<" ";
        // }
        int z=-1, o=-1, ans=0,fz=0,fo=0;
        rep(i,0,101){
            if(cnt[i]==1 && fz==0) { o=i; fz=1; }
            if(cnt[i]==0 && fo==0) { z=i; fo=1; }
        }
        // cout<<o<<" "<<z;
        if(z!=0 && o!=-1) cout<<o+z<<endl;
        else if(o==-1 && z!=0) cout<<z*2<<endl;
        else if(z==0) cout<<0<<endl;
        // cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        // rep(i,0,101){
        //     cout<<cnt[i]<<" ";
        // }
        int z=-1, o=-1, ans=0,fz=0,fo=0;
        rep(i,0,102){
            if(cnt[i]==1 && fz==0) { o=i; fz=1; }
            if(cnt[i]==0 && fo==0) { z=i; fo=1; }
        }
        // cout<<o<<" "<<z;
        if(z!=0 && o!=-1) cout<<o+z<<endl;
        else if(o==-1 && z!=0) cout<<z*2<<endl;
        else if(z==0) cout<<0<<endl;
        // cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        // rep(i,0,101){
        //     cout<<cnt[i]<<" ";
        // }
        int z=-2, o=-2, ans=0,fz=0,fo=0;
        rep(i,0,102){
            if(cnt[i]==1 && fz==0) { o=i; fz=1; }
            if(cnt[i]==0 && fo==0) { z=i; fo=1; }
        }
        // cout<<o<<" "<<z;

        if(z!=0 && o!=-2) cout<<o+z<<endl;
        else if(o==-2 && z!=0) cout<<z*2<<endl;
        else if(z==0) cout<<0<<endl;
        // cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        // rep(i,0,101){
        //     cout<<cnt[i]<<" ";
        // }
        int z=-1, o=-1, ans=0,fz=0,fo=0;
        rep(i,0,102){
            if(cnt[i]==1 && fz==0) { o=i; fz=1; }
            if(cnt[i]==0 && fo==0) { z=i; fo=1; }
        }
        cout<<o<<" "<<z;
        if(z!=0 && o!=-1) cout<<o+z<<endl;
        else if(o==-1 && z!=0) cout<<z*2<<endl;
        else if(z==0) cout<<0<<endl;
        // cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        // rep(i,0,101){
        //     cout<<cnt[i]<<" ";
        // }
        int z=-1, o=-1, ans=0,fz=0,fo=0;
        rep(i,0,101){
            if(cnt[i]==1 && fz==0) { o=i; fz=1; }
            if(cnt[i]==0 && fo==0) { z=i; fo=1; }
        }
        cout<<o<<" "<<z;
        if(z!=0 && o!=-1) cout<<o+z<<endl;
        else if(o==-1 && z!=0) cout<<z*2<<endl;
        else if(z==0) cout<<0<<endl;
        // cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        // rep(i,0,101){
        //     cout<<cnt[i]<<" ";
        // }
        int z=-2, o=-2, ans=0,fz=0,fo=0;
        rep(i,0,102){
            if(cnt[i]==1 && fz==0) { o=i; fz=1; }
            if(cnt[i]==0 && fo==0) { z=i; fo=1; }
        }
        // cout<<o<<" "<<z;

        if(z!=0 && o!=-1) cout<<o+z<<endl;
        else if(o==-2 && z!=0) cout<<z*2<<endl;
        else if(z==0) cout<<0<<endl;
        // cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        // rep(i,0,101){
        //     cout<<cnt[i]<<" ";
        // }
        int z=-1, o=-1, ans=0,fz=0,fo=0;
        rep(i,0,101){
            if(cnt[i]==1 && fz==0) { o=i; fz=1; }
            if(cnt[i]==0 && fo==0) { z=i; fo=1; }
        }
        // cout<<o<<" "<<z;
        if(z!=0) cout<<o+z<<endl;
        // if(o!=0 && o>z) cout<<2*z<<endl;
        else if(z==0) cout<<0<<endl;
        // cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(102);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        // rep(i,0,101){
        //     cout<<cnt[i]<<" ";
        // }
        // int z=-2, o=-2, ans=0,fz=0,fo=0;
        // rep(i,0,102){
        //     if(cnt[i]==1 && fz==0) { o=i; fz=1; }
        //     if(cnt[i]==0 && fo==0) { z=i; fo=1; }
        // }
        // // cout<<o<<" "<<z;

        // if(z!=0 && o!=-2) cout<<o+z<<endl;
        // else if(o==-2 && z!=0) cout<<z*2<<endl;
        // else if(z==0) cout<<0<<endl;
        int res = 0;
        int have = 2;
        for (int i=0; i<102; i++) {
    	if (cnt[i]==0) break;
    	have = MIN(have, cnt[i]);
    	res += have;
        }

        cout<<res<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(100);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        int i=0, ans=0;
        while(cnt[i]==2){
            i++;
            if(cnt[i]>=2){
                continue;
            }
            if(cnt[i]==0){
                ans = i*2;
                break;
            }
            ans = i;
        }
        while(cnt[i]==1){
            i++;
            if(cnt[i]==1){
                continue;
            }
            ans += i;
        }
        cout<<ans<<endl;
    }
}


#pragma GCC optimizer ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long int ll;
#define mp(a,b) make_pair(a,b)
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define inp(a,n) vl a(n);rep(i,0,n) cin>>a[i];
#define rep(i,a,b)  for(ll i=a;i<b;i++)
int main(){
    fastio;
    w(t) {
        ll n;
        cin>>n;
        vl a(n);
        vl cnt(100);
        rep(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
        }
        int i=0, ans=0;
        while(cnt[i]>=2){
            i++;
            if(cnt[i]>=2){
                continue;
            }
            if(cnt[i]==0){
                ans = i*2;
                break;
            }
            ans = i;
        }
        while(cnt[i]==1){
            i++;
            if(cnt[i]==1){
                continue;
            }
            ans += i;
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define forinc(i,a,b) for(int i=a;i<b;i++)
#define fordec(i,a,b) for(int i=a;i>b;i--)

using namespace std;

int main(){
    int tc,n,c,m1=0,m2=0,re;
    vector<int> a;
    vector<int> h;
    cin>>tc;
    forinc(t,0,tc){
        cin>>n;
        h.clear();
        m1=-1;
        m2=-1;
        forinc(i,0,102){
            h.push_back(0);
        }
        forinc(i,0,n){
            cin>>c;
            h[c] ++;
            a.push_back(c);
        }
        forinc(i,0,102){
            if(h[i]<1 && m1==-1){
                m1=i;
            }
            if(h[i]<2 && m2==-1){
                m2=i;
            }
        }
        cout<<m1+m2<<endl;
    };
}


#include <bits/stdc++.h>
#define ll long long
#define forinc(i,a,b) for(int i=a;i<b;i++)
#define fordec(i,a,b) for(int i=a;i>b;i--)

using namespace std;

int main(){
    int tc,n,c,m1=0,m2=0,re;
    vector<int> a;
    vector<int> h;
    cin>>tc;
    forinc(t,0,tc){
        cin>>n;
        h.clear();
        m1=-1;
        m2=-1;
        forinc(i,0,100){
            h.push_back(0);
        }
        forinc(i,0,n){
            cin>>c;
            h[c] ++;
            a.push_back(c);
        }
        forinc(i,0,100){
            if(h[i]<1 && m1==-1){
                m1=i;
            }
            if(h[i]<2 && m2==-1){
                m2=i;
            }
        }
        cout<<m1+m2<<endl;
    };
}


#include <bits/stdc++.h>
#define ll long long
#define forinc(i,a,b) for(int i=a;i<b;i++)
#define fordec(i,a,b) for(int i=a;i>b;i--)

using namespace std;

int main(){
    int tc,n,c,m1=0,m2=0,re;
    vector<int> a;
    vector<int> h;
    cin>>tc;
    forinc(t,0,tc){
        cin>>n;
        h.clear();
        m1=-1;
        m2=-1;
        forinc(i,0,102){
            h.push_back(0);
        }
        forinc(i,0,n){
            cin>>c;
            h[c] ++;
            a.push_back(c);
        }
        forinc(i,0,100){
            if(h[i]<1 && m1==-1){
                m1=i;
            }
            if(h[i]<2 && m2==-1){
                m2=i;
            }
        }
        cout<<m1+m2<<endl;
    };
}


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

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

    while(t--){
     int n;
     cin>>n;
     vector<int> arr(n);
     for(int i=0;i<n;i++)cin>>arr[i];

     int count[101];
     memset(count,0,sizeof(count));

     for(int i=0;i<n;i++){
         count[arr[i]]++;
     }

     if(count[0]==0)cout<<"0"<<endl;
     else if(count[0]==1){
        for(int i=1;i<101;i++){
            if(count[i]==0){cout<<i<<endl;break;}
        }
     }
     else{
       int a,b=-1;
       for(int i=1;i<101;i++){
           if(count[i]==0){
               a=i;b=i;
               break;
           }
           if(count[i]==1){a=i;break;}
       }
       if(b==-1){
       for(int i=a+1;i<101;i++){
           if(count[i]==0){b=i;break;}
       }
       }
       cout<<a+b<<endl;
     }

    }
}


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

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

    while(t--){
     int n;
     cin>>n;
     vector<int> arr(n);
     for(int i=0;i<n;i++)cin>>arr[i];

     int count[101];
     memset(count,0,sizeof(count));

     for(int i=0;i<n;i++){
         count[arr[i]]++;
     }

     if(count[0]==0)cout<<"0"<<endl;
     else if(count[0]==1){
        for(int i=1;i<101;i++){
            if(count[i]==0){cout<<i<<endl;break;}
        }
     }
     else{
       int a,b;
       for(int i=1;i<101;i++){
           if(count[i]<2){a=i;break;}
       }
       for(int i=a+1;i<101;i++){
           if(count[i]<2){b=i;break;}
       }
       cout<<a+b<<endl;
     }

    }
}


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

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

    while(t--){
     int n;
     cin>>n;
     vector<int> arr(n);
     for(int i=0;i<n;i++)cin>>arr[i];

     int count[101];
     memset(count,0,sizeof(count));

     for(int i=0;i<n;i++){
         count[arr[i]]++;
     }

     if(count[0]==0)cout<<"0"<<endl;
     else if(count[0]==1){
        for(int i=1;i<101;i++){
            if(count[i]==0){cout<<i<<endl;break;}
        }
     }
     else{
       int a,b=-1;
       for(int i=1;i<101;i++){
           if(count[i]==0){
               a=i;b=i;
               break;
           }
           if(count[i]==1){a=i;break;}
       }
       if(b==-1){
       for(int i=a+1;i<101;i++){
           if(count[i]<2){b=i;break;}
       }
       }
       cout<<a+b<<endl;
     }

    }
}


#include<bits/stdc++.h>
using namespace std;
int getmex(string s){
    if(s.size()==0){
        return 0;
    }
    int count=0;
    for(int i=0;i<s.size();i++){
        if((s[i]-'0')!=count){
            return count;
        }
        count++;
    }
    return count;
}
int subsetMex(int*arr, int n){
   string A="";
   string B="";
   A+=arr[0]+'0';
   for(int i=1;i<n;i++){
       if(arr[i]==(A[A.size()-1]-'0')){
           B+=arr[i]+'0';
       }
       else{
           A+=arr[i]+'0';
       }
   }

   int mexA=getmex(A);
   int mexB=getmex(B);

   return mexA+mexB;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int*arr=new int[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        cout<<subsetMex(arr,n)<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
int getmex(int s[], int n){
    if(n==0){
        return 0;
    }
    int count=0;
    for(int i=0;i<n;i++){
        if((s[i])!=count){
            return count;
        }
        count++;
    }
    return count;
}
int subsetMex(int*arr, int n){
   int A[101];
   int a=0;
   int B[101];
   int b=0;
   A[a]=arr[0];
   a++;
   for(int i=1;i<n;i++){
       if(arr[i]==A[a-1]){
           B[b]=arr[i];
           b++;
       }
       else{
           A[a]=arr[i];
           a++;
       }
   }

   int mexA=getmex(A,a);
   int mexB=getmex(B,b);

   return mexA+mexB;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int*arr=new int[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        cout<<subsetMex(arr,n)<<endl;

        delete []arr;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int getmex(int s[], int n){
    if(n==0){
        return 0;
    }
    int count=0;
    for(int i=0;i<n;i++){
        if(i!=0 && s[i]==s[i-1]){
            continue;
        }
        if((s[i])!=count){
            return count;
        }
        count++;
    }
    return count;
}
int subsetMex(int*arr, int n){
   int A[101];
   int a=0;
   int B[101];
   int b=0;
   A[a]=arr[0];
   a++;
   for(int i=1;i<n;i++){
       if(arr[i]==A[a-1]){
           B[b]=arr[i];
           b++;
       }
       else{
           A[a]=arr[i];
           a++;
       }
   }

   int mexA=getmex(A,a);
   int mexB=getmex(B,b);

   return mexA+mexB;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int*arr=new int[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        cout<<subsetMex(arr,n)<<endl;

        delete []arr;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int getmex(string s){
    if(s.size()==0){
        return 0;
    }
    int count=0;
    for(int i=0;i<s.size();i++){
        if((s[i]-'0')!=count){
            return count;
        }
        count++;
    }
    return count;
}
int subsetMex(int*arr, int n){
   string A="";
   string B="";
   A+=arr[0]+'0';
   for(int i=1;i<n;i++){
       if(arr[i]==(A[A.size()-1]-'0')){
           B+=arr[i]+'0';
       }
       else{
           A+=arr[i]+'0';
       }
   }

   int mexA=getmex(A);
   int mexB=getmex(B);

   return mexA+mexB;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;

        int*arr=new int[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        cout<<subsetMex(arr,n)<<endl;

        delete []arr;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using  namespace std;
int a[1001],f[1001];
int main(){
	int t,n,i,j,sum,ans;
	cin >> t;
	for(int i=1;i <= t;i++){
		cin >> n;
		memset(a,0,sizeof(a));
		memset(f,0,sizeof(f));
		for(int j=1;j <= n;j++){
			cin >> a[j];
			f[a[j]]++;
		}
		sort(a,a+n);
		sum = 0;ans = 0;
		for(int j=1;j <= n;j++){
			if(a[j] == sum && f[a[j]] > 0){
				sum++;
				ans++;
				f[a[j]]--;
			}
			else{
				if(a[j] > sum)break;
			}
		}
		sum = 0;
		for(int j=1;j <= n;j++){
			if(a[j] == sum && f[a[j]] > 0){
				sum++;
				ans++;
				f[a[j]]--;
			}
			else{
				if(a[j] > sum)break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int q, n, ans, pot[200], x;
int main()
{
    cin >> q;
    while(q--)
    {
        cin >> n;
        memset(pot, 0, sizeof(pot));
        ans = 0;
        for(int i = 1; i <= n; i++)
        {
            cin >> x;
            pot[x]++;
        }
        for(int k = 1; k <= 2; k++)
        {
            for(int i = 0; i <= 101; i++)
            {
                if(pot[i] > 0)
                {
                    pot[i]--;
                }
                else
                {
                    ans += i;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int t;
int n;
int a[105];
int q[105];
int main ()  {
	scanf ("%d", &t);
	while (t --) {
		memset (q, 0, sizeof(q));
		int mx = -1;
		scanf ("%d", &n);
		for (int i = 1; i <= n; i ++) {
			scanf ("%d", &a[i]);
			q[a[i]] ++;
			if (a[i] > mx)
				mx = a[i];
		}
		int ans = 0;
		for (int i = 0; i <= mx + 1; i ++) {
			if (q[i] == 0) {
				ans += i;
				break;
			}
		}
		for (int i = 0; i <= mx + 1; i ++) {
			if (q[i] <= 1) {
				ans += i;
				break;
			}
		}
		printf ("%d\n", ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
int t,n,a[105],f[105];
int main(){
    cin>>t;
    for(int i(0);i<t;++i){
    	cin>>n;
    	memset(a,0,sizeof(a));
    	memset(f,0,sizeof(f));
    	for(int j(0);j<n;++j){
    		cin>>a[j];
    		f[a[j]]++;
		}sort(a,a+n);int ans=0,num=0;
		for(int j(0);j<n;++j){
			if(a[j]==num&&f[a[j]]>0){
				num++;
				ans++;
				f[a[j]]--;
			}else{
				if(a[j]>num)break;
			}
		}num=0;
		for(int j(0);j<n;++j){
			if(a[j]==num&&f[a[j]]>0){
				num++;
				ans++;
				f[a[j]]--;
			}else{
				if(a[j]>num)break;
			}
		}cout<<ans<<endl;
	}
	return 0;
}


/*
@ author:pyyyyyy
-----思路------
对于本题而言，最优秀的无非就是两个连续的集合
对于不连续的集合来说，大的是没用的，所以要把数从小到大连续分
如果一旦出现不连续的情况，那么答案必定是最先出现的两个不连续数之和
如果这个做，比较复杂，需要特盘一些情况
本题一共没多少数，所以可以直接枚举
-----debug-------

*/

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

inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

const int N = 100001;
int t, n, a[N], vis[N];

int dfs(){
	int ret = 0;
	for(int j = 0; j <= 100; ++j){
		for(int i = 1; i <= 100; ++i){
			if(a[i] == j && !vis[i]){
				vis[i] = 1;
				ret++;
				break;
			}
			if(i == n) return ret;
		}
	}
	return ret;
}

int main()
{
	//	freopen(".in","r",stdin);
	//	freopen(".out","w",stdout);
	t = read();
	while(t--){
		int ans = 0;
		memset(vis, 0, sizeof(vis));
		n = read();
		for(int i = 1; i <= n; ++i) a[i] = read();
		sort(a + 1, a + 1 + n);
		ans += dfs();
		ans += dfs();
		cout << ans << '\n';
	}
	return 0;
}
/*
input：

output:

*/


#include<iostream>
#include<cstring>
using namespace std;
int a[105],b[105];
int main()
{
	int t;
	cin>>t;
	for (int i=1;i<=t;i++)
	{
		int n,x;
		cin>>n;
		for (int i=1;i<=n;i++)
		{
			cin>>x;
			if(a[x]) b[x]++;
			else a[x]++;
		}
		int h=0;
		for (int i=0;i<=n;i++)
		{
			if(!a[i])
			{
				h+=i;
				break;
			}
		}
		for (int i=0;i<=n;i++)
		{
			if(!b[i])
			{
				h+=i;
				break;
			}
		}
		cout<<h<<endl;
		for (int i=0;i<=105;i++) a[i]=b[i]=0;
	}
}


#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int n,a[105];
int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		memset(a,0,sizeof(a));
		int ans=0,flag=-1,end=0;
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			a[x]++;
		}
		for(int i=0;i<=105;i++){
			if(a[i]==0){
				end=i;
				break;
			}
			if(a[i]==1&&flag==-1){
				flag=i;
				continue;
			}
		}
		if(flag==-1&&end>0){
			cout<<end*2<<endl;
			continue;
		}
		cout<<max(end+flag,0)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t,n,a[110],b[110];
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		memset(b,0,sizeof(b));
		for(int i=0;i<n;i++){
			cin>>a[i];
			b[a[i]]++;//记录每个元素出现的次数
		}
		int ans1=-1,ans2=-1;
		for(int i=0;i<=n;i++){
			if(b[i]<2 && ans1==-1){
				ans1=i;
			}
			if(b[i]==0 && ans2==-1){
				ans2=i;
			}
		}
		cout<<ans1+ans2<<endl;
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
const int N=105;
int t,n,ans,flag,a[N];

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^48);ch=getchar();}
    return x*f;
}

int main(){
    t=read();
    while(t--){
        ans=flag=0;
        memset(a,0,sizeof(a));
        n=read();
        for(int i=1;i<=n;i++) a[read()]++;
        for(int i=0;i<=100;i++){
            if(a[i]==0){
                ans+=i*2;
                flag=1;
                break;
            }
            if(a[i]==1){
                ans+=i;
                //cout<<i<<endl;
                break;
            }
        }
        if(flag==1){
            printf("%d\n",ans);
            continue;
        }
        for(int i=0;i<=100;i++)
            if(a[i]==0){
                ans+=i;
                //cout<<i+1<<endl;
                break;
            }
        printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
int a[1024], b[1024];
bool aopy[1024];
int maxmex = 0;
int n, nb;
void bullshit(bool ifb, int dep) {
	if (dep == n) {
		int mexa = 0;
		int mexb = 0;
		for (int i = 1; i <= n; i++) {
			if (1);
		}
	}
}
int main() {
	int t = 0;
	for (std::cin >> t; t > 0; t--) {
		int mexa = 0;
		int mexb = 0;
		for (int i = 0; i <= 255; i++) {
			a[i] = 0;
			b[i] = 0;
			aopy[i] = false;
		}
		std::cin >> n;
		nb = n;
		for (int i = 1; i <= n; i++)
			std::cin >> a[i];
		std::sort(a + 1, a + 1 + n);
		for (int i = 1; i <= n; i++) {
			if (a[i] > mexa) {
				break;
			}
			else {
				if (a[i] != a[i + 1]) {
					aopy[i] = true;
					nb--;
					mexa++;
				}
			}
		}
		int k = 0;
		for (int j = 1; j <= n; j++) {
			if (aopy[j])continue;
			else {
				k++;
				b[k] = a[k];
			}
		}
		b[k + 1] = -1;
		for (int m = 1; m <= nb; m++) {
			if (b[m] > mexb)
				break;
			else
				if (b[m] != b[m + 1])
					mexb++;
		}
		maxmex = mexa + mexb;
		std::cout << maxmex << std::endl;
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  105
int t,n;
int a[N];
void process(){
    cin>>n;
    FOR(i,1,n) cin>>a[i];
    sort(a+1,a+1+n);
    int cnt=0;
    FOR(i,1,n){
        if (a[i]==0) ++cnt;
    }
    if (!cnt){
        cout<<0<<"\n";
    }
    else if (cnt>0) {
        int c[N],d[N],s=0;
        int cntc=0,cntd=0;
        bool ktg[N],ktv[N];
        memset(ktg,0,sizeof(ktg));
        memset(ktv,0,sizeof(ktv));
        FOR(i,1,n){
            if (ktg[a[i]]==0&&ktv[i]==0){
                c[++cntc]=a[i];
                ktv[i]=1;
                ktg[a[i]]=1;
            }
        }
        bool checkc=0;
        FOR(i,1,cntc-1){
            if (c[i+1]-c[i]>1){
                checkc=1;
                s+=(c[i]+1);
            }
        }
        if (checkc==0) s+=c[cntc]+1;

        bool checkd=0;
        FOR(i,1,n){
            if (ktv[i]==0){
                d[++cntd]=a[i];
            }
        }
        if (cnt==1){
            if (cntd>0) {s+=d[1]-1; cout<<s<<"\n"; return;}
            else {cout<<s<<"\n";return;}
        }
        FOR(i,1,cntd-1){
            if (d[i+1]-d[i]>1){
                s+=d[i]+1;
                checkd=1;
            }
        }
        if (checkd==0&&cntd>0) s+=d[cntd]+1;
        cout<<s<<"\n";
    }

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

}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  105
int t,n;
int a[N];
void process(){
    cin>>n;
    FOR(i,1,n) cin>>a[i];
    sort(a+1,a+1+n);
    int cnt=0;
    FOR(i,1,n){
        if (a[i]==0) ++cnt;
    }
    if (!cnt){
        cout<<0<<"\n";
    }
    else if (cnt==1) {
        FOR(i,1,n-1){
            if (a[i+1]-a[i]>1){
                cout<<a[i]+1<<"\n";
                break;
            }
        }
        cout<<a[n]+1<<"\n";
    }
    else {
        int x=0,s=0,cnt=0,v=0;
        bool kt[N];
        memset(kt,0,sizeof(kt));
        FOR(i,3,n){
            if (a[i]-x<=1){
                if (a[i]-x==1) kt[i]=1;
                x=a[i];
                continue;
            }
        }
        bool check=0;
        for(int i=n; i>=0; i--){
            if (kt[i]==1&&check==false){
                s+=a[i]+1;
                check=true;
            }
            if (check==true&&kt[i]==0){
                s+=a[i]+1;
                break;
            }
        }
        cout<<s<<"\n";
    }
}
int main(){
    _io;
    cin>>t;
    while(t--){
         process();
    }

}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  105
int t,n;
int a[N];
void process(){
    cin>>n;
    FOR(i,1,n) cin>>a[i];
    sort(a+1,a+1+n);
    int cnt=0;
    FOR(i,1,n){
        if (a[i]==0) ++cnt;
    }
    if (!cnt){
        cout<<0<<"\n";
    }
    else if (cnt>0) {
        int c[N],d[N],s=0;
        int cntc=0,cntd=0;
        bool ktg[N],ktv[N];
        memset(ktg,0,sizeof(ktg));
        memset(ktv,0,sizeof(ktv));
        FOR(i,1,n){
            if (ktg[a[i]]==0&&ktv[i]==0){
                c[++cntc]=a[i];
                ktv[i]=1;
                ktg[a[i]]=1;
            }
        }
        bool checkc=0;
        FOR(i,1,cntc-1){
            if (c[i+1]-c[i]>1){
                checkc=1;
                s+=(c[i]+1);
            }
        }
        if (checkc==0) s+=c[cntc]+1;
        bool checkd=0;
        FOR(i,1,n){
            if (ktv[i]==0){
                d[++cntd]=a[i];
            }
        }
        FOR(i,1,cntd-1){
            if (d[i+1]-d[i]>1){
                s+=d[i]+1;
                checkd=1;
            }
        }
        if (checkd==0&&cntd>0) s+=d[cntd]+1;
        cout<<s<<"\n";
    }

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

}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N  1000
int t,n;
int a[N];
void process(){
    cin>>n;
    FOR(i,1,n) cin>>a[i];
    sort(a+1,a+1+n);
    int cnt=0;
    FOR(i,1,n){
        if (a[i]==0) ++cnt;
    }
    if (!cnt){
        cout<<0<<"\n";
    }
    else if (cnt>0) {
        int c[N],d[N],s=0;
        int cntc=0,cntd=0;
        bool ktg[N],ktv[N];
        memset(ktg,0,sizeof(ktg));
        memset(ktv,0,sizeof(ktv));
        FOR(i,1,n){
            if (ktg[a[i]]==0&&ktv[i]==0){
                c[++cntc]=a[i];
                ktv[i]=1;
                ktg[a[i]]=1;
            }
        }
        bool checkc=0;
        FOR(i,1,cntc-1){
            if (c[i+1]-c[i]>1){
                checkc=1;
                s+=(c[i]+1);
                break;
            }
        }
        if (checkc==0) s+=(c[cntc]+1);

        bool checkd=0;
        FOR(i,1,n){
            if (ktv[i]==0){
                d[++cntd]=a[i];
            }
        }
        if (cnt==1){

            cout<<s<<"\n";return;
        }
        FOR(i,1,cntd-1){
            if (d[i+1]-d[i]>1){
                s+=(d[i]+1);
                checkd=1;
                break;
            }
        }
        if (checkd==0&&cntd>0) s+=d[cntd]+1;
        cout<<s<<"\n";
    }

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

}


#include <string>
#include <iostream>
#include <set>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <cmath>
#include <climits>
#include <cstdio>
#include <algorithm>
using namespace std;

vector<int> sort(vector<int>); // sorts the vector given as argument and returns it

typedef long long int lli;

bool contains(string s, char c) {
	for(size_t i(0); i < s.size(); i++) {
		if(s[i] == c) {
			return true;
		}
	}
	return false;
}

bool contains(vector<int> vec, int c) {
	for(size_t i(0); i < vec.size(); i++) {
		if(vec[i] == c) {
			return true;
		}
	}
	return false;
}

lli max(lli a, lli b) {
	return a < b ? b : a;
}

int maxElem(vector<int> vec) {
	int max(0);
	for(size_t i(0); i < vec.size(); i++) {
		if(max < vec[i]) {
			max = vec[i];
		}
	}
	return max;
}

void print_vector(vector<int> vec) {
	for(size_t i(0); i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << endl;
}

int main(void) {
	int t;
	cin >> t;
	for(int i(0); i < t; i++) {
		int n;
		cin >> n;
		vector<int> a(n);
		for(int i(0); i < n; i++) {
			cin >> a[i];
		}
		vector<int> occ(102);

		for(int i(0); i < n; i++) {
			occ[a[i]]++;
		}
		if(!contains(occ, 2)) {
			int count(1);
			int sum(0);
			for(size_t i(0); i < occ.size(); i++) {
				if(occ[i] == 0 && count) {
					count--;
					sum = i;
				}
			}
			cout << sum << endl;
		}
		else {
			int sum(0);
			int count0(1);
			int count1(1);
			for(size_t i(0); i < occ.size(); i++) {
				if(occ[i] == 0 && count0) {
					sum += i;
					count0--;
				}
			}
			for(size_t i(0); i < occ.size(); i++) {
				if((occ[i] == 1 || occ[i] == 0) && count1) {
					sum += i;
					count1--;
				}
			}
			cout << sum << endl;
		}

	}

	return 0;
}


#include <string>
#include <iostream>
#include <set>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <cmath>
#include <climits>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int lli;

int main(void) {

	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		int max(0);
		for(int i(0); i < n; i++) {
			cin >> a[i];
			if(a[i] > max) {
				max = a[i];
			}
		}

		vector<int> occurences(max+2);
		for(int i(0); i < n; i++) {
			occurences[a[i]] += 1;
		}
		bool more2 = false;
		for(int i(0); i < max+2; i++) {
			if(occurences[i] >= 2) {
				more2 = true;
				break;
			}
		}
		if(!more2) {
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 0) {
					cout << i << endl;
					break;
				}
			}
		}
		else {
			bool contains1 = false;
			int mex(0);
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 1) {
					contains1 = true;
					mex += i;
					break;
				}
			}
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 0) {
					mex += contains1 ? i : 2*i;
					break;
				}
			}
			cout << mex << endl;
		}

	}

    return 0;

}


#include <string>
#include <iostream>
#include <set>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <cmath>
#include <climits>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int lli;

int main(void) {

	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		int max(0);
		for(int i(0); i < n; i++) {
			cin >> a[i];
			if(a[i] > max) {
				max = a[i];
			}
		}

		vector<int> occurences(max+2);
		for(int i(0); i < n; i++) {
			occurences[a[i]] += 1;
		}
		bool contains2(false);
		for(int i(0); i < max+2; i++) {
			if(occurences[i] >= 2) {
				contains2 = true;
				break;
			}
		}

		if(!contains2) {
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 0) {
					cout << i << endl;
					break;
				}
			}
		}

		else {
			int mex(0);
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 0) {
					mex = i;
					break;
				}
			}
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 1) {
					mex += i;
					break;
				}
			}
			cout << mex << endl;

		}

	}

    return 0;

}


#include <string>
#include <iostream>
#include <set>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <cmath>
#include <climits>
#include <cstdio>
#include <algorithm>
using namespace std;

vector<int> sort(vector<int>); // sorts the vector given as argument and returns it

typedef long long int lli;

bool contains(string s, char c) {
	for(size_t i(0); i < s.size(); i++) {
		if(s[i] == c) {
			return true;
		}
	}
	return false;
}

bool contains(vector<int> vec, int c) {
	for(size_t i(0); i < vec.size(); i++) {
		if(vec[i] == c) {
			return true;
		}
	}
	return false;
}

lli max(lli a, lli b) {
	return a < b ? b : a;
}

int maxElem(vector<int> vec) {
	int max(0);
	for(size_t i(0); i < vec.size(); i++) {
		if(max < vec[i]) {
			max = vec[i];
		}
	}
	return max;
}

void print_vector(vector<int> vec) {
	for(size_t i(0); i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << endl;
}

int main(void) {
	int t;
	cin >> t;
	for(int i(0); i < t; i++) {
		int n;
		cin >> n;
		vector<int> a(n);
		for(int i(0); i < n; i++) {
			cin >> a[i];
		}
		vector<int> occ(102);
		if(occ.size() == 1) {
			cout << 0 << endl;
		}
		else {
			vector<int> setA;
			vector<int> setB;
			for(int i(0); i < n; i++) {
				occ[a[i]]++;
			}
			if(!contains(occ, 2)) {
				int count(1);
				int sum(0);
				for(size_t i(0); i < occ.size(); i++) {
					if(occ[i] == 0 && count) {
						count--;
						sum = i;
					}
				}
				cout << sum << endl;
			}
			else {
				int sum(0);
				int count0(1);
				int count1(1);
				for(size_t i(0); i < occ.size(); i++) {
					if(occ[i] == 0 && count0) {
						sum += i;
						count0--;
					}
				}
				for(size_t i(0); i < occ.size(); i++) {
					if(occ[i] == 1 && count1) {
						sum += i;
						count1--;
					}
				}
				cout << sum << endl;
			}

		}

	}

	return 0;
}


#include <string>
#include <iostream>
#include <set>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <cmath>
#include <climits>
#include <cstdio>
#include <algorithm>
using namespace std;

vector<int> sort(vector<int>); // sorts the vector given as argument and returns it

typedef long long int lli;

bool contains(string s, char c) {
	for(size_t i(0); i < s.size(); i++) {
		if(s[i] == c) {
			return true;
		}
	}
	return false;
}

bool contains(vector<int> vec, int c) {
	for(size_t i(0); i < vec.size(); i++) {
		if(vec[i] == c) {
			return true;
		}
	}
	return false;
}

lli max(lli a, lli b) {
	return a < b ? b : a;
}

int maxElem(vector<int> vec) {
	int max(0);
	for(size_t i(0); i < vec.size(); i++) {
		if(max < vec[i]) {
			max = vec[i];
		}
	}
	return max;
}

bool containsBigger(vector<int> vec, int c) {
	for(size_t i(0); i < vec.size(); i++) {
		if(vec[i] >= c) {
			return true;
		}
	}
	return false;
}

void print_vector(vector<int> vec) {
	for(size_t i(0); i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << endl;
}

int main(void) {
	int t;
	cin >> t;
	for(int i(0); i < t; i++) {
		int n;
		cin >> n;
		vector<int> a(n);
		for(int i(0); i < n; i++) {
			cin >> a[i];
		}
		vector<int> occ(102);

		for(int i(0); i < n; i++) {
			occ[a[i]]++;
		}
		if(!containsBigger(occ, 2)) {
			int count(1);
			int sum(0);
			for(size_t i(0); i < occ.size(); i++) {
				if(occ[i] == 0 && count) {
					count--;
					sum = i;
				}
			}
			cout << sum << endl;
		}
		else {
			int sum(0);
			int count0(1);
			int count1(1);
			for(size_t i(0); i < occ.size(); i++) {
				if((occ[i] == 0) && count0) {
					sum += i;
					count0--;
				}
			}
			for(size_t i(0); i < occ.size(); i++) {
				if((occ[i] == 1 || occ[i] == 0) && count1) {
					sum += i;
					count1--;
				}
			}
			if(occ[0] < 2) {
				sum = 0;
			}
			cout << sum << endl;
		}

	}

	return 0;
}


#include <string>
#include <iostream>
#include <set>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <cmath>
#include <climits>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int lli;

int main(void) {

	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		int max(0);
		for(int i(0); i < n; i++) {
			cin >> a[i];
			if(a[i] > max) {
				max = a[i];
			}
		}

		vector<int> occurences(max+2);
		for(int i(0); i < n; i++) {
			occurences[a[i]] += 1;
		}
		bool contains2(false);
		for(int i(0); i < max+2; i++) {
			if(occurences[i] >= 2) {
				contains2 = true;
				break;
			}
		}

		if(!contains2) {
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 0) {
					cout << i << endl;
					break;
				}
			}
		}

		else {
			int mex(0);
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 0) {
					mex = i;
					break;
				}
			}
			for(int i(0); i < max+2; i++) {
				if(occurences[i] <= 1) {
					mex += i;
					break;
				}
			}
			cout << mex << endl;

		}

	}

    return 0;

}


#include <string>
#include <iostream>
#include <set>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <cmath>
#include <climits>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int lli;

int main(void) {

	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		int max(0);
		for(int i(0); i < n; i++) {
			cin >> a[i];
			if(a[i] > max) {
				max = a[i];
			}
		}

		vector<int> occurences(max+2);
		for(int i(0); i < n; i++) {
			occurences[a[i]] += 1;
		}
		bool more2 = false;
		for(int i(0); i < max+2; i++) {
			if(occurences[i] >= 2) {
				more2 = true;
				break;
			}
		}
		if(!more2) {
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 0) {
					cout << i << endl;
					break;
				}
			}
		}
		else {
			int mex(0);
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 1) {
					mex += i;
					break;
				}
			}
			for(int i(0); i < max+2; i++) {
				if(occurences[i] == 0) {
					mex += i;
					break;
				}
			}
			cout << mex << endl;
		}

	}

    return 0;

}


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

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

        sort(arr.begin(), arr.end());

        int i = 0;
        int min1 = 0, min2 = 0;
        while(i<n && arr[i]<0) i++;

        for(i; i<n;){
            if(arr[i] > min1 && arr[i] > min2)
                break;
            if(i<n && arr[i] == min1)
                min1++, i++;
            if(i<n && arr[i] == min2){
                min2++, i++;
            }
            if(i<n && arr[i]<min1 && arr[i]<min2)
                i++;
        }

        cout << min1 + min2 << endl;
    }
}


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

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

        sort(arr.begin(), arr.end());
        for(int i = 0; i<n; i++) cout << arr[i] << " ";
        cout << endl;

        int i = 0;
        int min1 = 0, min2 = 0;
        //while(i<n && arr[i]<0) i++;

        for(i; i<n;){
            //cout << arr[i] << endl;
            if(arr[i] > min1 && arr[i] > min2)
                break;
            if(i<n && arr[i] == min1)
                min1++, i++;
            if(i<n && arr[i] == min2){
                min2++, i++;
            }
            if(i<n && !(arr[i] >= min1 && arr[i] >= min2))
                i++;
        }

        cout << min1 + min2 << endl;
    }
}


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

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

        sort(arr.begin(), arr.end());
        //for(int i = 0; i<n; i++) cout << arr[i] << " ";
        //cout << endl;

        int i = 0;
        int min1 = 0, min2 = 0;
        //while(i<n && arr[i]<0) i++;

        for(i; i<n;){
            //cout << arr[i] << endl;
            if(arr[i] > min1 && arr[i] > min2)
                break;
            if(i<n && arr[i] == min1)
                min1++, i++;
            if(i<n && arr[i] == min2){
                min2++, i++;
            }
            if(i<n && !(arr[i] >= min1 && arr[i] >= min2))
                i++;
        }

        cout << min1 + min2 << endl;
    }
}


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

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

        sort(arr.begin(), arr.end());

        int i = 0;
        int min1 = 0, min2 = 0;
        while(i<n && arr[i]<0) i++;

        for(i; i<n;){
            if(arr[i] > min1 && arr[i] > min2)
                break;
            if(i<n && arr[i] <= min1)
                min1++, i++;
            if(i<n && arr[i] <= min2){
                min2++, i++;
            }
        }

        cout << min1 + min2 << endl;
    }
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <cstdio>
using namespace std;
#define endl '\n'
#define space ' '

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n,num,point=1,a,b;
        cin >> n;
        vector<int> nums;
        vector<int> count(100);
        vector<int> n1(100);
        vector<int> n2(100);
        while (n--)
        {
            cin >> num;
            nums.push_back(num);
            count[num] += 1;
        }
        for (int i = 0; i < count.size();i++)
        {
            if (count[i] == 0) continue;
            else {
                if (count[i]%2==0)
                {
                    n1[i]++;
                    n2[i]++;
                } else if (count[i]%2==1)
                {
                    if (point) n1[i]++;
                    else n2[i]++;
                    point = !point;
                }
            }
        }
        for (int i = 0; i < n1.size();i++)
        {
            if (n1[i]==0)
            {
                a =i;
                break;
            }
        }
        for (int i = 0; i < n2.size();i++)
        {
            if (n2[i]==0)
            {
                b =i;
                break;
            }
        }
        cout << a + b << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <cstdio>
using namespace std;
#define endl '\n'
#define space ' '

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n,num,ans = 0;
        cin >> n;
        vector<int> nums;
        vector<int> count(101);
        while (n--)
        {
            cin >> num;
            nums.push_back(num);
            count[num] += 1;
        }
        for (int i = 0; i < count.size();i++)
        {
            if (count[i]==0)
                {
                    ans += i;
                    break;
                }
        }
        for (int i = 0; count[i] >= 2; i++,ans++);
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <cstdio>
using namespace std;
#define endl '\n'
#define space ' '

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n,num,a,b,ans;
        cin >> n;
        vector<int> nums;
        vector<int> count(100);
        while (n--)
        {
            cin >> num;
            nums.push_back(num);
            count[num] += 1;
        }
        sort(nums.begin(), nums.end());
        for (int i = 0; i < count.size();i++)
        {
            if (count[i] == 0)
            {
                ans = 2*i;
                break;
            }
            else if (count[i]%2==1)
                {
                    a = i;
                    for (int j = i + 1;j<count.size();j++)
                    {
                        if (find(nums.begin(), nums.end(),j)==nums.end())
                        {
                            b = j;
                            break;
                        }

                    }
                    ans = a + b;
                    break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <cstdio>
using namespace std;
#define endl '\n'
#define space ' '

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n,num,ans = 0;
        cin >> n;
        vector<int> nums;
        vector<int> count(100);
        while (n--)
        {
            cin >> num;
            nums.push_back(num);
            count[num] += 1;
        }
        for (int i = 0; i < count.size();i++)
        {
            if (count[i]==0)
                {
                    ans += i;
                    break;
                }
        }
        for (int i = 0; count[i] >= 2; i++,ans++);
        cout << ans << endl;
    }
    return 0;
}


# include <iostream>
# include <cstdio>
# include <cstring>

typedef long long ll;

int cnt[105];

void solve() {
	int n;
	std::cin >> n;

	memset(cnt, 0, sizeof(cnt));

	int t;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &t);
		cnt[t]++;
	}

	int ans = 0;

	for (int i = 0; i <= 100; i++) {
		if (!cnt[i]) {
			ans += i;
			break;
		}
	}

	for (int i = 0; i <= 100; i++) {
		if (cnt[i] <= 1) {
			ans += i;
			break;
		}
	}

	std::cout << ans << "\n";
}

int main() {
	int T;
	std::cin >> T;
	while (T-- ) {
		solve();
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <cmath>
# include <algorithm>
# include <cassert>
# include <vector>

typedef long long ll;

int a[105];

void solve() {
	int n;
	std::cin >> n;

	std::vector<int> v1;
	std::vector<int> v2;
	for (int i = 1; i <= n; i++) {
		std::cin >> a[i];

		v1.push_back(a[i]);
	}

	std::sort(a + 1, a + 1 + n);
	std::sort(v1.begin(), v1.end());
	v1.erase(std::unique(v1.begin(), v1.end()), v1.end());

	for (int l = 1, r; l <= n; l = r) {
		for (r = l; a[l] == a[r] && r <= n; r++) {

		}

		if (r - l >= 2) {
			v2.push_back(a[l]);
		}
	}

//	puts("v1");
//	for (int i = 0; i < v1.size(); i++) {
//		std::cout << v1[i] << " ";
//	}
//	puts("v2");
//	for (int i = 0; i < v2.size(); i++) {
//		std::cout << v2[i] << " ";
//	}
//	puts("");

	int ans = 0;

	int flag1 = 0;
	for (int i = 0 ; i < v1.size(); i++) {
		if (v1[i] != i) {
			ans += i;
			flag1 = 1;
			break;
		}
	}
	if (!flag1) {
		ans += v1.size();
	}

	int flag2 = 0;
	for (int i = 0; i < v2.size(); i++) {
		if (v2[i] != i) {
			ans += i;
			flag2 = 1;
			break;
		}
	}

	if (!flag2) {
		ans += v2.size();
	}

	std::cout << ans << "\n";

}

int main() {
	int T;
	std::cin >> T;
	while (T-- ) {
		solve();
	}////

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <cmath>
# include <algorithm>
# include <cassert>
# include <vector>

typedef long long ll;

int a[105];

void solve() {
	int n;
	std::cin >> n;

	std::vector<int> v1;
	std::vector<int> v2;
	for (int i = 1; i <= n; i++) {
		std::cin >> a[i];

		v1.push_back(a[i]);
	}

	std::sort(a + 1, a + 1 + n);
	std::sort(v1.begin(), v1.end());
	v1.erase(std::unique(v1.begin(), v1.end()), v1.end());

	for (int l = 1, r; l <= n; l = r) {
		for (r = l; a[l] == a[r] && r <= n; r++) {

		}

		if (r - l >= 2) {
			v2.push_back(a[l]);
		}
	}

//	puts("v1");
//	for (int i = 0; i < v1.size(); i++) {
//		std::cout << v1[i] << " ";
//	}
//	puts("v2");
//	for (int i = 0; i < v2.size(); i++) {
//		std::cout << v2[i] << " ";
//	}
//	puts("");

	int ans = 0;

	int flag1 = 0;
	for (int i = 0 ; i < v1.size(); i++) {
		if (v1[i] != i) {
			ans += i;
			flag1 = 1;
			break;
		}
	}
	if (!flag1) {
		ans += v1.size();
	}

	int flag2 = 0;
	for (int i = 0; i < v2.size(); i++) {
		if (v2[i] != i) {
			ans += i;
			flag2 = 1;
			break;
		}
	}

	if (!flag2) {
		ans += v2.size();
	}

	std::cout << ans << "\n";

}

int main() {
	int T;
	std::cin >> T;
	while (T-- ) {
		solve();
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <cmath>
# include <algorithm>
# include <cassert>
# include <vector>

typedef long long ll;

int cnt[105];

void solve() {
	int n;
	std::cin >> n;

	memset(cnt, 0, sizeof(cnt));

	int t;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &t);
		cnt[t]++;
	}

	int ans = 0;

	for (int i = 0; i <= 100; i++) {
		if (!cnt[i]) {
			ans += i;
			break;
		}
	}

	for (int i = 0; i <= 100; i++) {
		if (cnt[i] <= 1) {
			ans += i;
			break;
		}
	}

	std::cout << ans << "\n";
}

int main() {
	int T;
	std::cin >> T;
	while (T-- ) {
		solve();
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <cmath>
# include <algorithm>
# include <cassert>
# include <vector>

typedef long long ll;

int a[105];

void solve() {
	int n;
	std::cin >> n;
	for (int i = 1; i <= n; i++) {
		std::cin >> a[i];
	}

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

	std::vector<int> v1;
	std::vector<int> v2;

	int ans = 0;
	for (int l = 1, r; l <= n; l = r) {
		for (r = l; a[l] == a[r] && r <= n; r++) {

		}

		v1.push_back(a[l]);
		if (r == n) {
			if (a[l] != a[r]) {
				v1.push_back(a[l]);
				v1.push_back(a[r]);
				break;
			}

			if (r - l >= 1) {
				v2.push_back(a[l]);
			}
			break;
		}

		if (r - l >= 2) {
			v2.push_back(a[l]);
		}
	}

	v1.erase(std::unique(v1.begin(), v1.end()), v1.end());
	v2.erase(std::unique(v2.begin(), v2.end()), v2.end());

	int flag1 = 0;
	for (int i = 0; i < v1.size(); i++) {
		if (v1[i] != i) {
		//	std::cout << "i " << i << " " << v1[i] << "\n";
			ans += i;
			flag1 = 1;
			break;
		}
	}

//	puts("v1");
//	for (int i = 0; i < v1.size(); i++) {
//		std::cout << v1[i] << "\n";
//	}
//
//	puts("v2");
//	for (int i = 0; i < v2.size(); i++)  {
//		std::cout << v2[i] << "\n";
//	}
//	puts("-------------");

	if (!flag1) {
		ans += v1.size();
	//	puts("sssssssssss");
	}

//	std::cout << ans << " -> ans\n";

	int flag2 = 0;
	for (int i = 0; i < v2.size(); i++) {
		if (v2[i] != i) {
			ans += i; 		//std::cout << ans << "!!!->ans\n";
			flag2 = 1;
			break;
		}
	}

	if (!flag2) {
		ans += v2.size();
	}

//	puts("ans ");
	std::cout << ans << "\n";
}

int main() {
	int T;
	std::cin >> T;
	while (T-- ) {
		solve();
	}

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        long long int n,i,x,z;
        cin>>n;
        long long int a[n],b[101]={0};
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            b[a[i]]++;
        }
        for(i=1;i<101;i++)
        {
            if(b[i]==0)
           { x=i;
            break;}
        }
        for(i=1;i<101;i++)
        {
            if(b[i]<=1)
           { z=i;
            break;}
        }
        cout<<x+z<<"\n";
    }
}


#include<iostream>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        long long int n,i,x,z;
        cin>>n;
        long long int a[n],b[101]={0};
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            b[a[i]]++;
        }
        for(i=0;i<101;i++)
        {
            if(b[i]==0)
           { x=i;
            break;}
        }
        for(i=x;i<101;i++)
        {
            if(b[i]<=1)
           { z=i;
            break;}
        }
        cout<<x+z<<"\n";
    }
}


#include<iostream>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        long long int n,i,x,z;
        cin>>n;
        long long int a[n],b[101]={0};
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            b[a[i]]++;
        }
        for(i=0;i<101;i++)
        {
            if(b[i]==0)
           { x=i;
            break;}
        }
        for(i=0;i<101;i++)
        {
            if(b[i]<=1)
           { z=i;
            break;}
        }
        cout<<x+z<<"\n";
    }
}


#include<iostream>
#include <algorithm>
#include <iterator>
#include<vector>
#include <bits/stdc++.h>
using namespace std;

int mex(int a[], int size)
{
    sort(a, a+size);

    int i=0;
    while(1)
    {
        bool exists = std::find(a, a+size, i) != a+size;
        if(exists==true)
            i++;
        else
        {
            break;
        }
    }
    return i;
}

int main()
{
    int t;
    cin>>t;
    int n;
    int sum[t];
    for(int i=0;i<t;i++)
    {
        cin>>n;
        int arr[n];
        for(int j=0;j<n;j++)
        {
            cin>>arr[j];
        }
        sort(arr, arr+n);
        int a_size=n;
        int b_size=n;
        int A[n];
        int B[n];
        int a=0, b=0;
        for(int j=0;j<n;j++)
        {
            if(arr[j]==arr[j+1])
            {
                B[b++]=arr[j];
            }
            else
            {
                A[a++]=arr[j];
            }
        }
        a_size=a;
        b_size = b;

        int ma=mex(A, a_size);

        int mb=mex(B, b_size);

        sum[i]=ma+mb;
    }
    for(int i=0;i<t;i++)
    {
        cout<<sum[i]<<endl;
    }
}


#include<iostream>
#include <algorithm>
#include <iterator>
#include<vector>
#include <bits/stdc++.h>
using namespace std;

int mex(int a[], int size)
{
    sort(a, a+size);

    int i=0;
    while(1)
    {
        bool exists = std::find(a, a+size, i) != a+size;
        if(exists==1)
            i++;
        else
            break;
    }
    return i;
}

int main()
{
    int t;
    cin>>t;
    int n;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        int arr[n];
        for(int j=0;j<n;j++)
        {
            cin>>arr[j];
        }
        sort(arr, arr+n);
        int a_size=n;
        int b_size=n;
        int A[n];
        int B[n];
        int a=0, b=0;
        for(int j=0;j<n;j++)
        {
            if(arr[j]==arr[j+1])
            {
                B[b++]=arr[j];
            }
            else
            {
                A[a++]=arr[j];
            }
        }
        a_size=a+1;
        b_size = b+1;
        int ma=mex(A, a_size);

        int mb=mex(B, b_size);

        cout<<ma+mb;
    }
}


#include<iostream>
#include <algorithm>
#include <iterator>
#include<vector>
#include <bits/stdc++.h>
using namespace std;

int mex(int a[], int size)
{
    sort(a, a+size);

    int i=0;
    while(1)
    {
        bool exists = std::find(a, a+size, i) != a+size;
        if(exists==1)
            i++;
        else
            break;
    }
    return i;
}

int main()
{
    int t;
    cin>>t;
    int n;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        int arr[n];
        for(int j=0;j<n;j++)
        {
            cin>>arr[j];
        }
        sort(arr, arr+n);
        int a_size=n;
        int b_size=n;
        int A[n];
        int B[n];
        int a=0, b=0;
        for(int j=0;j<n;j++)
        {
            if(arr[j]==arr[j+1])
            {
                B[b++]=arr[j];
            }
            else
            {
                A[a++]=arr[j];
            }
        }
        a_size=a+1;
        b_size = b+1;
        int ma=mex(A, a_size);

        int mb=mex(B, b_size);

        cout<<ma+mb<<endl;
    }
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int x,y,z,n,c;
int a[1000000],b[10000];
int main() {
	int _;
	for (scanf("%d", &_); _; _--) {
		memset(a, 0, size(a));
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &x);
			a[x]++;
		}
		int q = -1, d = -1;
		for (int i = 1; i <= 101; i++) {
			if (q == -1 && a[i] == 1) {
				q = i;
			}
			if (!a[i]) {
				d = i; break;
			}
		}
		if (q == -1)
			printf("%d\n", 2 * d);
		else printf("%d\n", q + d);//
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int x,y,z,n,c;
int a[1000000],b[10000];
int main() {
	int _;
	for (scanf("%d", &_); _; _--) {
		memset(a, 0, sizeof(a));
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &x);
			a[x]++;
		}
		int q = -1, d = -1;
		for (int i = 0; i <= 101; i++) {
			if (q == -1 && a[i] == 1) {
				q = i;
			}
			if (!a[i]) {
				d = i; break;
			}
		}
		if (q == -1)
			printf("%d\n", 2 * d);
		else printf("%d\n", q + d);
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int x,y,z,n,c;
int a[1000000],b[10000];
int main() {
	int _;
	for (scanf("%d", &_); _; _--) {
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &x);
			a[x]++;
		}
		int q = -1, d = -1;
		for (int i = 1; i <= 101; i++) {
			if (q == -1 && a[i] == 1) {
				q = i;
			}
			if (!a[i]) {
				d = i; break;
			}
		}
		if (q == -1)
			printf("%d\n", 2 * d);
		else printf("%d\n", q + d);
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int x,y,z,n,c;
int a[1000000],b[10000];
int main() {
	int _;
	for (scanf("%d", &_); _; _--) {
		memset(a, 0, sizeof(a));
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &x);
			a[x]++;
		}
		int q = -1, d = -1;
		for (int i = 1; i <= 101; i++) {
			if (q == -1 && a[i] == 1) {
				q = i;
			}
			if (!a[i]) {
				d = i; break;
			}
		}
		if (q == -1)
			printf("%d\n", 2 * d);
		else printf("%d\n", q + d);
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int x,y,z,n,c;
int a[1000000],b[10000];
int main() {
	int _;
	for (scanf("%d", &_); _; _--) {
		memset(a, 0, size(a));
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &x);
			a[x]++;
		}
		int q = -1, d = -1;
		for (int i = 1; i <= 101; i++) {
			if (q == -1 && a[i] == 1) {
				q = i;
			}
			if (!a[i]) {
				d = i; break;
			}
		}
		if (q == -1)
			printf("%d\n", 2 * d);
		else printf("%d\n", q + d);
	}
	return 0;
}


#include <bits/stdc++.h>;

using namespace std;

int dem[1001];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        memset(dem,0,sizeof(dem));
        while(n--){
            int k;
            cin>>k;
            dem[k]++;
        }
    int x=2,i=0,ans=0;
    while(i<1000 && x>0){
        if(dem[i]<x){
            x-=2-dem[i];
            ans+=i*(2-dem[i]);
        }
    }
        cout<<ans<<"\n";
    }


#include <bits/stdc++.h>;

using namespace std;

int dem[1001];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        memset(dem,0,sizeof(dem));
        while(n--){
            int k;
            cin>>k;
            dem[k]++;
        }
    int x=2,i=0,ans=0;
    while(i<1000 && x>0){
        if(dem[i]<x){
            x-=2-dem[i];
            ans+=i*(2-dem[i]);
        }
        i++;
    }
        cout<<ans<<"\n";
    }
}


// Example program
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
int main()
{
int t;
cin>>t;
    int dem[101];
while(t--){
    int n;
    cin>>n;
    memset(dem,0,sizeof(dem));
    for(int i=1;i<=n;i++){
        int k;
        cin>>k;
        dem[k]++;
    }
    int ans=0;
    int i=0,d=0,x=2;
    if (dem[i]==0) ans=0;
    else if(dem[i]&1)
    {while(i<1000 && dem[i]!=0) i++;
    ans=i;
    }
    else
    while(i<1000 && d<2){
        if(dem[i]<x) {
            ans+=i*(min((2-dem[i]),(2-d)));
            d+=2-dem[i];
            x-=2-dem[i];
        }
        i++;
    }
        cout<<ans<<"\n";
}

}


// Example program
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
int main()
{
int t;
cin>>t;
    int dem[101];
while(t--){
    int n;
    cin>>n;
    memset(dem,0,sizeof(dem));
    for(int i=1;i<=n;i++){
        int k;
        cin>>k;
        dem[k]++;
    }
    int ans=0;
    int i=0,d=0;
    while(i<1000 && d<2){
        if(dem[i]<2) {
            ans+=i*(min((2-dem[i]),(2-d)));
            d+=2-dem[i];
        }
        i++;
    }
        cout<<ans<<"\n";
}

}


#include <bits/stdc++.h>;

using namespace std;

int dem[1001];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        memset(dem,0,sizeof(dem));
        while(n--){
            int k;
            cin>>k;
            dem[k]++;
        }
    int x=2,i=0,ans=0;
    while(i<1000 && x>0){
        if(dem[i]<x){
            x-=2-dem[i];
            ans+=i*(2-dem[i]);
        }
    }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>;

using namespace std;

int dem[1001];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        memset(dem,0,sizeof(dem));
        while(n--){
            int k;
            cin>>k;
            dem[k]++;
        }
    int x=2,i=0,ans=0;
    while(i<1000 && x>0){
        if(dem[i]<x){
            ans+=i*(x-dem[i]);
            x-=2-dem[i];
        }
        i++;
    }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>;

using namespace std;

int dem[1001];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        memset(dem,0,sizeof(dem));
        while(n--){
            int k;
            cin>>k;
            dem[k]++;
        }
    int x=2,i=0,ans=0;
    while(i<1000 && x>0){
        if(dem[i]<x){
            x-=2-dem[i];
            ans+=i*(x-dem[i]);
        }
        i++;
    }
        cout<<ans<<"\n";
    }
}


#include <bits/stdc++.h>;

using namespace std;

int dem[1001];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        memset(dem,0,sizeof(dem));
        while(n--){
            int k;
            cin>>k;
            dem[k]++;
        }
    int x=2,i=0,ans=0;
    while(i<1000 && x>0){
        if(dem[i]<x){
            x-=2-dem[i];
            ans+=i*(2-dem[i]);
        }
        i++;
    }
        cout<<ans<<"\n";
    }


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

#define ll long long

int find_mex(vector<int> v)
{
    if(v.empty())
        return 0;

    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=i)
            return i;
    }
    return (int)v.size();
}

int main()
{
    int T,n;
    cin>>T;

    while(T--)
    {
        cin>>n;
        int arr[101],k;

        fill_n(arr,n,0);
        for(int i=0;i<n;i++)
        {
            cin>>k;
            arr[k]++;
        }

        int ans=0,i;

        i=0;
        while(i<100)
        {
            if(arr[i]>=2)
            {
                i++;
                continue;
            }
            else if(arr[i]==1)
            {
                ans=i;
                i++;
                for(;i<=100;i++)
                {
                    if(i==100)
                        ans+=i;
                    else if(arr[i]==0)
                    {
                        ans+=i;
                        i=200;
                    }
                }
            }
            else if(arr[i]==0)
            {
                ans=i*2;
                break;
            }
        }

        cout<<ans<<"\n";
    }
    return 0;
}


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

#define ll long long

int find_mex(vector<int> v)
{
    if(v.empty())
        return 0;

    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=i)
            return i;
    }
    return (int)v.size();
}

int main()
{
    int T,n;
    cin>>T;

    while(T--)
    {
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];

        sort(arr,arr+n);

        vector<int> v1,v2;

        int i=0;
        while(i<n)
        {
            int x,y;
            x=arr[i];
            if(i+1<n)
                y=arr[++i];

            i++;
            if(x==y)
                v1.push_back(x),v2.push_back(y);
            else
            {
                v1.push_back(x);
                v1.push_back(y);
                while(i<n)
                {
                    v1.push_back(arr[i]);
                    i++;
                }
            }

        }

        int x=find_mex(v1);
        int y=find_mex(v2);
        cout<<x+y<<"\n";
    }
    return 0;
}


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

#define ll long long

int find_mex(vector<int> v)
{
    if(v.empty())
        return 0;

    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=i)
            return i;
    }
    return (int)v.size();
}

int main()
{
    int T,n;
    cin>>T;

    while(T--)
    {
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];

        sort(arr,arr+n);

        vector<int> v1,v2;

        int i=0;
        while(i<n)
        {
            int x,y;
            if(i>0)
            {
                if(arr[i-1]==arr[i])
                {
                    i++;
                    continue;
                }
            }
            x=arr[i];
            if(i+1<n)
                y=arr[++i];

            i++;
            v1.push_back(x);
            v2.push_back(y);
        }

        int x=find_mex(v1);
        int y=find_mex(v2);
        cout<<x+y<<"\n";
    }
    return 0;
}


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

#define ll long long

int find_mex(vector<int> v)
{
    if(v.empty())
        return 0;

    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=i)
            return i;
    }
    return (int)v.size();
}

int main()
{
    int T,n;
    cin>>T;

    while(T--)
    {
        cin>>n;
        int arr[101],k;

        fill_n(arr,101,0);
        for(int i=0;i<n;i++)
        {
            cin>>k;
            arr[k]++;
        }

        int ans=0,i;

        i=0;
        while(i<100)
        {
            if(arr[i]>=2)
            {
                i++;
                continue;
            }
            else if(arr[i]==1)
            {
                ans=i;
                i++;
                for(;i<=100;i++)
                {
                    if(i==100)
                        ans+=i;
                    else if(arr[i]==0)
                    {
                        ans+=i;
                        i=200;
                    }
                }
            }
            else if(arr[i]==0)
            {
                ans=i*2;
                break;
            }
        }

        cout<<ans<<"\n";
    }
    return 0;
}


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

#define ll long long

int find_mex(vector<int> v)
{
    if(v.empty())
        return 0;

    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=i)
            return i;
    }
    return (int)v.size();
}

int main()
{
    int T,n;
    cin>>T;

    while(T--)
    {
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];

        sort(arr,arr+n);

        vector<int> v1,v2;

        int i=0;
        while(i<n)
        {
            int x,y;
            if(i>0)
            {
                if(arr[i-1]==arr[i])
                {
                    i++;
                    continue;
                }
            }
            x=arr[i];
            if(i+1<n)
                y=arr[++i];

            i++;
            if(x==y)
                v1.push_back(x),v2.push_back(y);
            else
            {
                v1.push_back(x);
                v1.push_back(y);
                while(i<n)
                {
                    v1.push_back(arr[i]);
                    i++;
                }
            }

        }

        int x=find_mex(v1);
        int y=find_mex(v2);
        cout<<x+y<<"\n";
    }
    return 0;
}


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

#define ll long long

int find_mex(vector<int> v)
{
    if(v.empty())
        return 0;

    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=i)
            return i;
    }
    return (int)v.size();
}

int main()
{
    int T,n;
    cin>>T;

    while(T--)
    {
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];

        sort(arr,arr+n);

        vector<int> v1,v2;

        int i=0;
        while(i<n)
        {
            int x,y;
            if(arr[i]==arr[i-1] && i>0)
            {
                i++;
                continue;
            }
            x=arr[i];
            if(i+1<n)
                y=arr[++i];

            i++;
            if(x==y)
                v1.push_back(x),v2.push_back(y);
            else
            {
                v1.push_back(x);
                v1.push_back(y);
                while(i<n)
                {
                    v1.push_back(arr[i]);
                    i++;
                }
            }

        }

        int x=find_mex(v1);
        int y=find_mex(v2);
        cout<<x+y<<"\n";
    }
    return 0;
}


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

int main()
{
   long long int t,b,n,i,x,y,p,q,r,c,d,f,m,sum,j,l,flag,ans;
   cin>>t;
   while(t--)
   {
       ans=0,p=0,c=0;
       cin>>n;
       vector<long long>v1,v2;
       long long int a[n],arr[110]={0};
        for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0)
            c++;
        }
        sort(a,a+n);
        if(c==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        else if(c==1)
        {
            for(i=0;i<n;i++)
            if(a[i]>ans)
            ans++;
            cout<<ans+1<<endl;
        }
        else
        {
            for(i=0;i<n;i++)
            {
                arr[a[i]]++;
            }
            for(i=0;i<110;i++)
            {
                if(arr[i]>=2)
                {
                    v1.push_back(i);
                    v2.push_back(i);
                }
                else if(arr[i]==1)
                {
                    v1.push_back(i);

                }
            }
            sort(v1.begin(),v1.end());
            sort(v2.begin(),v2.end());
            ans=0;
            for(i=0;i<v1.size();i++)
            if(v1[i]>ans)
            ans++;
            if(ans==v1[v1.size()-1])
                p=ans+1;
            else
                p=ans;
            ans=0;
            for(i=0;i<v2.size();i++)
            if(v2[i]>ans)
            ans++;
            if(ans==v2[v2.size()-1])
                q=ans+1;
            else
                q=ans;

            cout<<p+q<<endl;
            /*for(i=0;i<v1.size();i++)
                cout<<v1[i]<<" ";
            cout<<endl;
            for(i=0;i<v2.size();i++)
                cout<<v2[i]<<" ";
            cout<<endl;*/
            //cout<<p<<" "<<q<<endl;

        }

   }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,i,j,n,ans;
    cin>>n;
    while(t--)
    {
        ans=0;
        cin>>n;
        long long int a[n],arr[110]={0};
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            arr[a[i]]++;
        }
        i=0;
        while(arr[i]>0 && i<110)
        {
            arr[i]--;
            i++;
        }
        ans+=i;
        i=0;
        while(arr[i]>0 && i<110)
        {
            arr[i]--;
            i++;
        }
        ans+=i;
        cout<<ans<<endl;
    }
}


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

int main()
{
   long long int t,b,n,i,x,y,p,q,r,c,d,f,m,sum,j,l,flag,ans;
   cin>>t;
   while(t--)
   {
       ans=0,p=0,c=0;
       cin>>n;
       long long int a[n],arr[105]={0};
       for(i=0;i<n;i++){
        cin>>a[i];
        arr[a[i]]++;
       }
       i=0;
       while(arr[i]>0 && i<105)
       {
           arr[i]--;
           i++;
       }
       ans+=i;
       i=0;
       while(arr[i]>0 && i<105)
       {
           arr[i]--;
           i++;
       }
       ans+=i;
       cout<<ans<<endl;

   }
}


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

int main()
{
   long long int t,b,n,i,x,y,p,q,r,c,d,f,m,sum,j,l,flag,ans;
   cin>>t;
   while(t--)
   {
       ans=0,p=0,c=0;
       cin>>n;
       vector<long long>v1,v2;
       long long int a[n],arr[110]={0};
        for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0)
            c++;
        }
        sort(a,a+n);
        if(c==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        else if(c==1)
        {
            for(i=0;i<n;i++)
            if(a[i]>ans)
            ans++;
            cout<<ans+1<<endl;
        }
        else
        {
            for(i=0;i<n;i++)
            {
                arr[a[i]]++;
            }
            for(i=0;i<110;i++)
            {
                if(arr[i]>1)
                {
                    v1.push_back(arr[i]);
                    v2.push_back(arr[i]);
                }
                else if(arr[i]==1)
                {
                    if(arr[i]%2)
                    v1.push_back(arr[i]);
                    else
                    v2.push_back(arr[i]);
                }
            }
            sort(v1.begin(),v1.end());
            sort(v2.begin(),v2.end());
            ans=0;
            for(i=0;i<v1.size();i++)
            if(v1[i]>ans)
            ans++;
            p=ans;
            ans=0;
            for(i=0;i<v2.size();i++)
            if(v2[i]>ans)
            ans++;
            q=ans;
            cout<<p+q+1<<endl;

        }

   }
}


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

int main()
{
   long long int t,b,n,i,x,y,p,q,r,c,d,f,m,sum,j,l,flag,ans;
   cin>>t;
   while(t--)
   {
       ans=0,p=0,c=0;
       cin>>n;
       vector<long long>v1,v2;
       long long int a[n],arr[110]={0};
        for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0)
            c++;
        }
        sort(a,a+n);
        if(c==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        else if(c==1)
        {
            for(i=0;i<n;i++)
            if(a[i]>ans)
            ans++;
            cout<<ans+1<<endl;
        }
        else
        {
            for(i=0;i<n;i++)
            {
                arr[a[i]]++;
            }
            for(i=0;i<110;i++)
            {
                if(arr[i]>1)
                {
                    v1.push_back(arr[i]);
                    v2.push_back(arr[i]);
                }
                else if(arr[i]==1)
                {
                    v1.push_back(arr[i]);
                }
            }
            sort(v1.begin(),v1.end());
            sort(v2.begin(),v2.end());
            ans=0;
            for(i=0;i<v1.size();i++)
            if(v1[i]>ans)
            ans++;
            p=ans;
            ans=0;
            for(i=0;i<v2.size();i++)
            if(v2[i]>ans)
            ans++;
            q=ans;
            cout<<p+q+1<<endl;

        }

   }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,i,j,n,ans;
    cin>>t;
    while(t--)
    {
        ans=0;
        cin>>n;
        long long int a[n],arr[110]={0};
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            arr[a[i]]++;
        }
        i=0;
        while(arr[i]>0 && i<110)
        {
            arr[i]--;
            i++;
        }
        ans+=i;
        i=0;
        while(arr[i]>0 && i<110)
        {
            arr[i]--;
            i++;
        }
        ans+=i;
        cout<<ans<<endl;
    }
}


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

int main()
{
   long long int t,b,n,i,x,y,p,q,r,c,d,f,m,sum,j,l,flag,ans;
   cin>>t;
   while(t--)
   {
       ans=0;
       cin>>n;
       long long int a[n];
        for(i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
        if(a[0]!=0)
        {
            cout<<"0"<<endl;
            continue;
        }
        if(a[0]==0 && a[1]==0)
            p=1;
        else
            p=0;
        for(i=0;i<n;i++)
        if(a[i]>ans)
        ans++;

        cout<<p+ans+1<<endl;
   }
}


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

int main()
{
   long long int t,b,n,i,x,y,p,q,r,c,d,f,m,sum,j,l,flag,ans;
   cin>>t;
   while(t--)
   {
       ans=0,p=0;
       cin>>n;
       long long int a[n];
        for(i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
        if(a[0]!=0)
        {
            cout<<"0"<<endl;
            continue;
        }
        else if(a[0]==0 && a[1]==0)
        {
            p=1;
            for(i=1;i<n;i++)
            if(a[i]>ans)
            ans++;

        }
        else
        {
            p=0;
            for(i=0;i<n;i++)
            if(a[i]>ans)
            ans++;
        }

        cout<<p+ans+1<<endl;
   }
}


#include<iostream>
#include<cstring>
using namespace std;
int a[105];
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,ans=0;
		cin>>n;
		memset(a,0,sizeof a);
		for(int i=1;i<=n;i++)
		{
			int x;
			cin>>x;
			a[x]++;
		}
		for(int i=0;i<=101;i++)
		{
			if(a[i]==0)
			{
				cout<<ans<<endl;
				break;
			}
			if(a[i]==1) ans++;
			if(a[i]>=2) ans+=2;
		}
	}
	return 0;
}