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