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