#include <bits/stdc++.h>
const unsigned long long PRIME = 257;
static inline unsigned long long mult_prime(unsigned long long n) {
  return n + (n << 8);
}
int rabinKarpMatcher(char *T, char *P, unsigned long long *t,
                     unsigned long long *d) {
  int n = strlen(T);
  int m = strlen(P);
  --T;
  --P;
  unsigned long long h = 1;
  for (int i = 0; i <= 11; ++i)
    if ((m - 1) & (1 << i)) h *= d[i];
  unsigned long long p = 0;
  t[0] = 0;
  for (int i = 1; i <= m; ++i) {
    p = mult_prime(p) + P[i];
    t[0] = mult_prime(t[0]) + T[i];
  }
  for (int s = 0; s <= n - m; ++s) {
    if (p == t[s]) {
      if (1) {
        return 1;
      }
    }
    if (s < n - m) t[s + 1] = mult_prime(t[s] - T[s + 1] * h) + T[s + m + 1];
  }
  return 0;
}
int main() {
  assert(sizeof(unsigned long long) == 8);
  unsigned long long d[64];
  d[0] = PRIME;
  for (int i = 1; i < 64; ++i) d[i] = d[i - 1] * d[i - 1];
  char *T = (char *)malloc(1000000 + 1);
  if (T == NULL) {
    printf("memory shortage.\n");
    return 1;
  }
  unsigned long long *t =
      (unsigned long long *)malloc((1000000 + 1) * sizeof(unsigned long long));
  if (t == NULL) {
    printf("memory shortage.\n");
    free(T);
    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, t, d));
  }
  free(T);
  free(t);
  return 0;
}
