#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, v;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> v;
    if (v == 2)
      cout << "2"
           << "\n";
    else {
      if (v % 2)
        cout << "1"
             << "\n";
      else
        cout << "0"
             << "\n";
    }
  }
}
