#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  int n[q];
  for (int i = 0; i < q; i++) {
    cin >> n[i];
  }
  for (int i = 0; i < q; i++) {
    if (n[i] % 2 == 0 && n[i] != 2)
      cout << "0" << endl;
    else if (n[i] == 2)
      cout << "2" << endl;
    else
      cout << "1" << endl;
  }
  return 0;
}
