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