#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
bool uax(T &a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool uin(T &a, const T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> &p) {
  out << p.first << ' ' << p.second;
  return out;
}
mt19937 rnd(1928);
int n, q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> n;
    if (n <= 4) {
      if (n == 2) {
        cout << 2;
      }
      if (n == 3) {
        cout << 1;
      }
      if (n == 4) {
        cout << 0;
      }
    } else {
      if (n % 2 == 0)
        cout << 0;
      else
        cout << 1;
    }
    cout << "\n";
  }
}
