#include <bits/stdc++.h>
using namespace std;
long long a, t, b, c, n, i, j, k, l, m;
int main() {
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> n;
    if (n == 2)
      cout << 2 << "\n";
    else if (n % 2 == 0)
      cout << 0 << "\n";
    else
      cout << 1 << "\n";
  }
}
