#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
bool isPrime(int n) {
  for (int i = 2; i <= n / i; ++i) {
    if (n % i) {
      return false;
    }
    return true;
  }
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int n;
    cin >> n;
    if (n == 2) {
      cout << 2 << endl;
    } else if (!isPrime(n))
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
}
