#include <bits/stdc++.h>
using namespace std;
long long g, f, d, t, y, flag, n;
int main() {
  cin >> f;
  while (f--) {
    cin >> d;
    if (d == 2)
      cout << 2 << endl;
    else {
      if (d % 2 == 0)
        cout << 0 << endl;
      else
        cout << 1 << endl;
    }
  }
  return 0;
}
