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