#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
const long long mod = 1e9 + 7;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long M = 10 + 10;
const long long N = 200 * 1000 + 10;
int main() {
  faster();
  int q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    if (n == 1) {
      cout << 3 << endl;
    } else if (n == 2) {
      cout << 2 << endl;
    } else
      cout << n % 2 << endl;
  }
}
