#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<math.h>
#include<string.h>
#include<deque>
#include<string>
#include<queue>
#include<cstring>
#include<string>
#include<numeric>
#include<bitset>
#include<array>
#include<stack>
using namespace std;
#define lowbit(x) x & ( -x )
#define endl '\n'
#define itn long long
#define int long long
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define ull unsigned long long
//const int p = 131;
const ull hx = 13331;
int dx[6] = { 0,1,0,-1 };
int dy[6] = { 1,0,-1,0 };
const int N = 10004;
int ans[32] = { 1,2,2,2,2,4,4,4,4,4,4,4,4,4,4,4,4,4,4,8,8,8,8,8,8,8,16,16,16,16,32,32 };
int a[32];
void tt()
{
for (int i = 0; i < 32; i++)
cin >> a[i];
int now = a[0];
sort(a, a + 32);
for(int i=0;i<32;i++)
if (a[i] == now)
{
cout << ans[i] << endl;
return;
}
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
tt();
}
}