#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) {
      cout << 3 << endl;
    } else if (v[i] == 2) {
      cout << 2 << endl;
    } else if (v[i] & 1 == 1) {
      cout << 1 << endl;
    } else
      cout << 0 << endl;
  }
}
