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