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