#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, k, q;
const int INF = 1e9 + 5;
const int MAXN = 3e5 + 5;
const ll mod = 998244353;
mt19937 rng(
    (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  cin >> n;
  if (n == 2) {
    cout << 2 << endl;
  } else {
    cout << (n & 1) ? '1' : '0';
    cout << endl;
  }
}
int main() {
  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  };
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
