#include<bits/stdc++.h>
using namespace std;
const int N = 40;
int a[N];
bool cmd(int x,int y){
return x > y;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t;
cin >> t;
int num[40];
num[1] = 1;
for(int i = 2;i <= 5; ++i){
num[i] = 2;
}
for(int i = 6;i <= 19; ++i){
num[i] = 4;
}
for(int i = 20;i <= 26; ++i){
num[i] = 8;
}
for(int i = 27;i <= 30; ++i){
num[i] = 16;
}
num[31] = num[32] = 32;
while(t--){
for(int i = 1;i <= 32; ++i){
cin >> a[i];
}
int x = a[1];
int ans = 0;
sort(a + 1,a + 33,cmd);
for(int i = 1;i <=32; ++i){
if(x == a[i]){
ans = nums[i];
break;
}
}
cout << ans << '\n';
}
}