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