#include <bits/stdc++.h>
using namespace std;
int d, b, c, n, i, a[1000], j, l, p;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 2)
      cout << "2" << endl;
    else
      cout << a[i] % 2 << endl;
  }
}
