#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int num;
  cin >> num;
  int arr[num];
  int ans[num];
  for (int i = 0; i < num; i++) {
    cin >> arr[i];
    if (arr[i] == 2)
      ans[i] = 2;
    else if (arr[i] == 3)
      ans[i] = 1;
    else if (arr[i] % 2 == 0)
      ans[i] = 0;
    else
      ans[i] = 1;
  }
  for (auto i : ans) cout << i << '\n';
  return 0;
}
