#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  int q;
  cin >> q;
  vector<int> ans(q);
  for (int i = 0; i < q; i++) {
    cin >> x;
    if (x == 2)
      ans[i] = 2;
    else if (x % 2 == 0)
      ans[i] = 0;
    else
      ans[i] = 1;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
  return 0;
}
