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