#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
int q;
int n;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> n;
    if (n <= 4)
      cout << 4 - n << '\n';
    else if (n & 1)
      cout << 1 << '\n';
    else
      cout << 0 << '\n';
  }
}
