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