#include <bits/stdc++.h>
using namespace std;
const int N=200000+5;
int n,ans;
int a[N];
int main(){
freopen ("and_sorting.in","r",stdin);
freopen ("and_sorting.out","w",stdout);
int T;
scanf("%d",&T);
for (int tt=1;tt<=T;tt++){
scanf("%d",&n);
ans=(1<<20)-1;
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
if (a[i]!=i-1){
ans=ans&a[i];
}
}
printf("%d\n",ans);
}
return 0;
}