#include <bits/stdc++.h>
#pragma GCC omptimize("unroll-loops")
#pragma GCC omptimize("игорь говно")
#pragma GCC optimize("no-stack-protector")
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int INF32 = 2009000999;
const long long INF64 = 4e18;
const int sz = 1e6;
const int mod = 1e9 + 7;
const long double EPS = 1e-18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  int cnt = 0;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n;
    if (((n % 2) == 0) && (n > 2))
      cout << 0 << endl;
    else {
      while (((n % 2) != 0) || (n <= 2)) {
        n++;
        cnt++;
      }
      cout << cnt << endl;
      cnt = 0;
    }
  }
  return 0;
}
