#include <bits/stdc++.h>
using namespace std;
long long dem1 = 0, maxx, j, k, dem = 0, n, b, dem2 = 0;
const int e = 2 * 1e5;
long long u = 0, d = 1, r = 0, l = 0;
long long a[100000];
string s;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> j;
    if (j % 2 == 0) {
      if (j == 2) {
        cout << 2 << endl;
      } else if (j == 0) {
        cout << 4 << endl;
      } else {
        cout << 0 << endl;
      }
    } else {
      cout << 1 << endl;
    }
  }
}
