#include <bits/stdc++.h>
const long long INF = 1e18 + 100;
using namespace std;
void run() {
  long long n;
  cin >> n;
  if (n <= 4) {
    cout << 4 - n << endl;
    return;
  }
  cout << (n % 2) << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) run();
  return 0;
}
