#include <bits/stdc++.h>
using namespace std;
void f(long long n);
int main() {
  long long n, q;
  cin >> q;
  while (q--) {
    cin >> n;
    f(n);
  }
}
void f(long long n) {
  if (n == 2) {
    cout << 2 << endl;
  } else if (n % 2 == 0) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
}
