#include <bits/stdc++.h>
const double INT_MAX = (1LL << DBL_MANT_DIG) - 1LL;
const double INT_MIN = -((1LL << DBL_MANT_DIG) - 1LL);
double add(double a, double b) {
  double res = a + b;
  assert(res >= INT_MIN && res <= INT_MAX);
  ;
  return res;
}
double mult(double a, double b) {
  double res = a * b;
  assert(res >= INT_MIN && res <= INT_MAX);
  ;
  return res;
}
double sub(double a, double b) {
  double res = a - b;
  assert(res >= INT_MIN && res <= INT_MAX);
  ;
  assert(a - res == b && res + b == a);
  return res;
}
double mod(double a, double b) {
  double res = fmod(a, b);
  if (res < -0.0) res += b;
  return res;
}
double modulo_powered_number(double base, int power, double modulo) {
  int max_digit = ceil(log2(power));
  double mem[max_digit + 1];
  mem[0] = mod(base, modulo);
  for (int i = 1; i <= max_digit; ++i)
    mem[i] = mod(mult(mem[i - 1], mem[i - 1]), modulo);
  double res = 1;
  for (int i = 0; i <= max_digit; ++i)
    if (power & (1 << i)) res = mod(mult(res, mem[i]), modulo);
  return res;
}
bool isEqual(char *start1, char *end1, char *start2, char *end2) {
  assert(end1 - start1 == end2 - start2);
  while (start1 <= end1) {
    if (*start1 != *start2) return false;
    ++start1;
    ++start2;
  }
  return true;
}
int rabinKarpMatcher(char *T, char *P, double d, double q) {
  int n = strlen(T);
  int m = strlen(P);
  --T;
  --P;
  double h = modulo_powered_number(d, m - 1, q);
  double p = 0;
  double t[n - m + 1];
  t[0] = 0;
  for (int i = 1; i <= m; ++i) {
    p = mod(add(mult(d, p), P[i]), q);
    t[0] = mod(add(mult(d, t[0]), T[i]), q);
  }
  for (int s = 0; s <= n - m; ++s) {
    if (p == t[s]) {
      if (isEqual(P + 1, P + m, T + s + 1, T + s + m)) {
        return 1;
      }
    }
    if (s < n - m)
      t[s + 1] =
          mod(add(mult(d, sub(t[s], mult(T[s + 1], h))), T[s + m + 1]), q);
  }
  return 0;
}
int main() {
  assert(DBL_MANT_DIG == 53);
  char *T = (char *)malloc(1000000 + 1);
  if (T == NULL) {
    printf("memory shortage.\n");
    return 1;
  }
  scanf("%s", T);
  int q = 0;
  scanf("%d", &q);
  char P[1000 + 1];
  for (int i = 0; i < q; ++i) {
    scanf("%s", P);
    printf("%d\n", rabinKarpMatcher(T, P, 256, (1 << 25) - 39));
  }
  free(T);
  return 0;
}
