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