#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 55;
const int inf = 1e9 + 77;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
map<long long, long long> mp;
map<long long, long long> mp1;
map<int, int> mp2;
vector<long long> v;
vector<int> v1;
vector<int> vo;
set<long long> c;
long long x[2 * MAX];
long long y[MAX];
long long poww(long long x, long long y) {
  if (y == 0) return 1;
  long long s = poww(x, y / 2);
  s = (s * s);
  if (y % 2 == 1) s = (s * x);
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    if (n == 2)
      cout << 2 << endl;
    else if (n & 1)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
