#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, nr, v[101];
  bool found = false;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) {
    nr = v[i];
    if (nr == 2)
      cout << 2 << endl;
    else {
      if (nr % 2 == 0)
        cout << 0 << " ";
      else
        cout << 1 << " ";
    }
  }
  return 0;
}
