#include "bits/stdc++.h"
using namespace std;
int main()
{
int N = 2024;
ios::sync_with_stdio(0);
vector<int> a(N + 1); set<int> s;
for (int i = 0, x = 0;i <= N;i++) {
a[i] = x;
s.insert(x);
for (int j = 0;j < 15;j++)
for (int k = 0;k < 15;k++)
s.insert(x ^ (1 << j) ^ (j == k ? 0 : (1 << k)));
while (s.find(x) != s.end())x++;
}
int t; cin >> t;
vector<vector<int> > v(15);
cout << "15\n";
for (int i = 0;i < 15;i++) {
for (int j = 0;j <= N;j++)
if (a[j] >> i & 1)
v[i].emplace_back(j);
for (int j : v[i])cout << j << ' ';
cout << endl;
}
while (t--)
{
int s = 0, i, j;
for (i = 0;i < 15;i++) {
int x = -1;
(cin >> x);
if (x) s |= 1 << i;
}
for (i = 0;i <= N;i++)
if (__builtin_popcount(a[i] ^ s) <= 1)break;
cout << i << endl;
}
}