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