#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  int a;
  cin >> q;
  while (q) {
    int e = 0;
    cin >> a;
    e = (a / 2) - 1;
    if (e < 1) {
      e = 1;
    }
    int n = 0, req = 0;
    while (n < a) {
      n = 2 * (e + 1);
      e++;
    }
    req = n - a;
    cout << req << endl;
    q--;
  }
  return 0;
}
