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