#include <bits/stdc++.h>
using namespace std;
int N(int a) {
  if (a != 2) {
    if (a % 2 == 0) {
      return 0;
    }
  }
  if (a % 2 != 0) {
    return 1;
  } else {
    return 2;
  }
}
int main() {
  int num, rop;
  cin >> num;
  vector<int> ans(num + 1);
  for (int i = 1; i < num + 1; i++) {
    cin >> rop;
    ans[i] = N(rop);
  }
  for (int i = 1; i < num + 1; i++) {
    cout << ans[i] << endl;
  }
}
