#include <iostream>
#include <vector>
#include <string>
using namespace std;
string flip(string s)
{
string out = "";
for (unsigned int i = 0; i < s.length(); i++)
{
if (s[i] == '0')
out += '1';
if (s[i] == '1')
out += '0';
}
return out;
}
string bittijono = "0";
char hankiBitti(unsigned int paikka)
{
if (bittijono.size() < paikka)
return bittijono[paikka - 1];
string out = "0";
while(out.size() < paikka)
{
out += flip(out);
}
if (out.size() > bittijono.size())
bittijono = out;
return out[paikka - 1];
}
int main()
{
int count;
cin >> count;
vector<int> n;
while (count > 0)
{
int num;
cin >> num;
n.push_back(num);
count--;
}
for (unsigned int i = 0; i < n.size(); i++)
{
cout << hankiBitti(n[i]) << endl;
}
return 0;
}