#include <bits/stdc++.h>
using namespace std;
int i = 0;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    if (a < 4) {
      cout << 4 - a << endl;
    } else {
      if (a % 2 == 0) {
        cout << '0' << endl;
      } else {
        cout << '1' << endl;
      }
    }
  }
  return 0;
}
