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