#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    if (a == 2)
      cout << a << endl;
    else if (a % 2 == 0)
      cout << a - a << endl;
    else
      cout << a - a + 1 << endl;
  }
}
