#include <bits/stdc++.h>
using namespace std;
template <typename T>
string join(vector<T> vec, string separator = "") {
  string result = "";
  for (int i = 0; i < vec.size(); i++) {
    result += to_string(vec[i]) + (i < vec.size() - 1 ? separator : "");
  }
  return result;
}
int main(int argc, const char* argv[]) {
  int queries;
  cin >> queries;
  vector<int> answers;
  for (int i = 0; i < queries; i++) {
    int input;
    cin >> input;
    if (input < 4) {
      answers.push_back(4 - input);
    } else {
      answers.push_back((input & 1));
    }
  }
  cout << join(answers, "\n") << endl;
}
