#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B> p) {
  return out << "(" << p.first << ',' << p.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& v) {
  out << "[";
  for (int i{}; i < v.size(); i++) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << "]";
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    if (n == 2)
      cout << 2 << endl;
    else {
      if (n % 2 == 0)
        cout << 0 << endl;
      else
        cout << 1 << endl;
    }
  }
}
