#include <bits/stdc++.h>
int main(int argc, char** argv) {
  int32_t num_queries;
  std::cin >> num_queries;
  for (int32_t i = 0; i < num_queries; i++) {
    int32_t num_sticks;
    std::cin >> num_sticks;
    if (num_sticks == 2)
      std::cout << 2 << std::endl;
    else if (num_sticks % 2 == 0)
      std::cout << 0 << std::endl;
    else
      std::cout << 1 << std::endl;
  }
  return 0;
}
