#include <bits/stdc++.h>
int main() {
  short q{0};
  std::cin >> q;
  long unsigned n{2};
  while (q) {
    std::cin >> n;
    if (n == 2) {
      std::cout << "2\n";
    } else if (n % 2 == 0) {
      std::cout << "0\n";
    } else {
      std::cout << "1\n";
    }
    --q;
  }
  return 0;
}
