#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (long long i = 0LL; i < q; i++) {
    long long n;
    cin >> n;
    if (n == 2LL) {
      cout << 2LL << endl;
      continue;
    }
    if (n % 2LL == 0LL) {
      cout << 0LL << endl;
    } else {
      cout << 1LL << endl;
    }
  }
  return 0;
}
