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