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