#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, a;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> a;
    if (a <= 4) {
      cout << 4 - a << endl;
    } else {
      cout << a % 2 << endl;
    }
  }
}
