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