#include <bits/stdc++.h>
using namespace std;
long long aran(long long n) {
  long long ara[n];
  for (long long i = 0; i < n; i++) {
    cin >> ara[i];
  }
}
int main() {
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    if (n & 1)
      cout << 1 << endl;
    else {
      if (n == 2)
        cout << 2 << endl;
      else
        cout << 0 << endl;
    }
  }
  return 0;
  ;
}
