#include <bits/stdc++.h>
int in() {
  int n = 0, c = getchar_unlocked();
  do n = 10 * n + (c & 0xf), c = getchar_unlocked();
  while (c >= '0');
  return n;
}
char text[1000005];
char pattern[10005];
int g[10005];
int next[10005], skip[258];
int bmMatch(char *text, int len, char *pattern, int patlen, int *skip,
            int *next) {
  int i, j;
  i = patlen - 1;
  while (i < len) {
    j = patlen - 1;
    while (j >= 0 && text[i] == pattern[j]) i--, j--;
    if (j < 0) return 1;
    if (skip[text[i]] >= next[j])
      i += skip[text[i]];
    else
      i += next[j];
  }
  return 0;
}
int bmSkip(int *skip, int slen, char *pattern, int patlen) {
  int j;
  if (slen < 256) return -1;
  for (j = 0; j < 256; j++) skip[j] = patlen;
  for (j = 0; j < patlen - 1; j++) skip[pattern[j]] = patlen - 1 - j;
  return 0;
}
int bmNext(int *next, int nlen, char *pattern, int patlen) {
  int j, k, s;
  for (j = 0; j < patlen; j++) next[j] = 2 * patlen - 1 - j;
  j = patlen;
  for (k = patlen - 1; k >= 0; k--) {
    g[k] = j;
    while (j != patlen && pattern[j] != pattern[k]) {
      next[j] = (next[j] <= patlen - 1 - k) ? next[j] : patlen - 1 - k;
      j = g[j];
    }
    j--;
  }
  s = j;
  for (j = 0; j < patlen; j++) {
    next[j] = (next[j] <= s + patlen - j) ? next[j] : s + patlen - j;
    if (j >= s) s = g[s];
  }
  return 0;
}
int main() {
  int Q, c, tlen, plen;
  int a, fa, b, fb;
  char *pos;
  fa = 1, pos = text;
  *pos++ = a = getchar_unlocked();
  while ((c = getchar_unlocked()) > ' ') {
    *pos++ = c;
    if (a != c) fa = 0;
  }
  *pos = 0;
  tlen = pos - text;
  Q = in();
  while (Q--) {
    fb = 1, pos = pattern;
    *pos++ = b = getchar_unlocked();
    while ((c = getchar_unlocked()) > ' ') {
      *pos++ = c;
      if (b != c) fb = 0;
    }
    *pos = 0;
    plen = pos - pattern;
    if (fa && fb && a == b)
      putchar_unlocked('0' + (tlen >= plen));
    else {
      bmSkip(skip, 256, pattern, plen);
      bmNext(next, plen, pattern, plen);
      putchar_unlocked(
          '0' + bmMatch(text, tlen - (pos - text), pattern, plen, skip, next));
    }
    putchar_unlocked('\n');
  }
  return 0;
}
