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