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