import java.util.Scanner;
/**
*
* @author ronij
*/
public class Simppeli {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int count = input.nextInt();
int[] lookup = new int[count];
byte[] table = new byte[count];
for (int i = 0; i < count; i++) {
lookup[i] = input.nextInt();
}
long[] time = new long[2];
time[0] = System.currentTimeMillis();
byte[] source = new byte[1048576];
int power;
for (int i = 0; i < 20; i++) {
power = (int)Math.pow(2,i);
for (int u = 0; u < power; u++) {
if (source[u] == 0){
source[power + u] = 1;
}
else{
source[power + u] = 0;
}
}
}
for (int i = 0; i < count; i++) {
table[i] = source[lookup[i] - 1];
}
//time[1] = System.currentTimeMillis();
//System.out.println(Arrays.toString(table));
for (int i = 0; i < count; i++) {
System.out.println(table[i]);
}
//System.out.println(time[1] - time[0]);
}
}