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