#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long p = n % 2;
    if (n < 4)
      cout << 4 - n << "\n";
    else
      cout << p << "\n";
  }
  return 0;
}
