#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n;
  cin >> n;
  int h, res;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    cin >> h;
    a.push_back(h);
  }
  for (int i = 0; i < n; i++) {
    h = a[i];
    res = 0;
    if (h < 4) {
      res += 4 - h;
      h = 4;
    }
    if (h % 2 != 0) {
      res++;
    }
    cout << res << "\n";
  }
  return 0;
}
