#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  long long n;
  cin >> x;
  for (int i = 1; i <= x; i++) {
    cin >> n;
    if (n == 2) {
      cout << 2 << "\n";
    } else if (n > 2 && n % 2 == 0)
      cout << 0 << "\n";
    else if (n > 2 && n % 2 != 0)
      cout << 1 << "\n";
  }
  return 0;
}
