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