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