#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, n, results[100], i{0};
  cin >> q;
  int x = q;
  while (q--) {
    cin >> n;
    if (n <= 4) {
      results[i] = 4 - n;
      i++;
    } else {
      results[i] = (n % 2 ? 1 : 0);
      i++;
    }
  }
  for (int j = 0; j < x; j++) {
    cout << results[j] << endl;
  }
  return 0;
}
