#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long q;
  cin >> q;
  for (long long qq = 0; qq < q; ++qq) {
    long long n;
    cin >> n;
    if (n < 4) {
      cout << 4 - n << '\n';
      continue;
    } else {
      cout << n % 2 << '\n';
    }
  }
}
