#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#define ll long long

ll t, n;

ll summ(ll x) {
  ll s = 0;
  while (x > 0) {
    s += x % 10;
    x /= 10;
  }
  return s;
}

ll doo(ll x) {
  ll s = 0;
  for (ll i = 2; i * i <= x; i++) {
    while(x % i == 0) {
       x /= i;
       s += summ(i);
    }
  }
  if (x > 1) s += summ(x);
  return s;
}


int main() {

  scanf("%lld", &t);
  while (t--) {
    scanf("%lld", &n);
    if (doo(n) == summ(n)) printf("1");
    else printf("0");
    printf("\n");

  }
  
  return 0;
}