#include <bits/stdc++.h>
using namespace std;
unsigned char mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
void getBuckets(unsigned char *s, int *bkt, int n, int K, int cs,
                bool end = true) {
  fill(bkt, bkt + K + 1, 0);
  for (int i = 0; i < int(n); ++i)
    bkt[(cs == sizeof(int) ? ((int *)s)[i] : ((unsigned char *)s)[i])]++;
  for (int i = 0, tmp = 0; i < int(K + 1); ++i)
    tmp += bkt[i], bkt[i] = end ? tmp : tmp - bkt[i];
}
void induceSAl(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n,
               int K, int cs, bool end = false) {
  getBuckets(s, bkt, n, K, cs, end);
  for (int i = 0; i < int(n); ++i)
    if (SA[i] > 0 && !!!(t[(SA[i] - 1) >> 3] & mask[(SA[i] - 1) & 7]))
      SA[bkt[(cs == sizeof(int) ? ((int *)s)[SA[i] - 1]
                                : ((unsigned char *)s)[SA[i] - 1])]++] =
          SA[i] - 1;
}
void induceSAs(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n,
               int K, int cs, bool end = true) {
  getBuckets(s, bkt, n, K, cs, end);
  for (int i = int(n - 1); i >= int(0); --i)
    if (SA[i] > 0 && !!(t[(SA[i] - 1) >> 3] & mask[(SA[i] - 1) & 7]))
      SA[--bkt[(cs == sizeof(int) ? ((int *)s)[SA[i] - 1]
                                  : ((unsigned char *)s)[SA[i] - 1])]] =
          SA[i] - 1;
}
void SA_IS(unsigned char *s, int *SA, int n, int K = 128, int cs = 1) {
  unsigned char t[(n >> 3) + 1];
  int bkt[K + 1], n1 = 0, name = 0;
  t[(n - 2) >> 3] = (0) ? (mask[(n - 2) & 7] | t[(n - 2) >> 3])
                        : ((~mask[(n - 2) & 7]) & t[(n - 2) >> 3]),
               t[(n - 1) >> 3] = (1) ? (mask[(n - 1) & 7] | t[(n - 1) >> 3])
                                     : ((~mask[(n - 1) & 7]) & t[(n - 1) >> 3]);
  for (int i = int(n - 2 - 1); i >= int(0); --i)
    t[(i) >> 3] =
        (((cs == sizeof(int) ? ((int *)s)[i] : ((unsigned char *)s)[i]) <
              (cs == sizeof(int) ? ((int *)s)[i + 1]
                                 : ((unsigned char *)s)[i + 1]) ||
          ((cs == sizeof(int) ? ((int *)s)[i] : ((unsigned char *)s)[i]) ==
               (cs == sizeof(int) ? ((int *)s)[i + 1]
                                  : ((unsigned char *)s)[i + 1]) &&
           !!(t[(i + 1) >> 3] & mask[(i + 1) & 7]))))
            ? (mask[(i)&7] | t[(i) >> 3])
            : ((~mask[(i)&7]) & t[(i) >> 3]);
  getBuckets(s, bkt, n, K, cs);
  fill(SA, SA + n, -1);
  for (int i = int(1); i < int(n); ++i)
    if ((i > 0 && !!(t[(i) >> 3] & mask[(i)&7]) &&
         !!!(t[(i - 1) >> 3] & mask[(i - 1) & 7])))
      SA[--bkt[(cs == sizeof(int) ? ((int *)s)[i] : ((unsigned char *)s)[i])]] =
          i;
  induceSAl(t, SA, s, bkt, n, K, cs);
  induceSAs(t, SA, s, bkt, n, K, cs);
  for (int i = 0; i < int(n); ++i)
    if ((SA[i] > 0 && !!(t[(SA[i]) >> 3] & mask[(SA[i]) & 7]) &&
         !!!(t[(SA[i] - 1) >> 3] & mask[(SA[i] - 1) & 7])))
      SA[n1++] = SA[i];
  fill(SA + n1, SA + n, -1);
  for (int i = 0, tmp = -1; i < int(n1); ++i) {
    int pos = SA[i], diff = false;
    for (int d = 0; d < n && !diff; d++) {
      diff = (cs == sizeof(int) ? ((int *)s)[pos + d]
                                : ((unsigned char *)s)[pos + d]) !=
                 (cs == sizeof(int) ? ((int *)s)[tmp + d]
                                    : ((unsigned char *)s)[tmp + d]) ||
             !!(t[(pos + d) >> 3] & mask[(pos + d) & 7]) !=
                 !!(t[(tmp + d) >> 3] & mask[(tmp + d) & 7]);
      if (!diff && d &&
          ((pos + d > 0 && !!(t[(pos + d) >> 3] & mask[(pos + d) & 7]) &&
            !!!(t[(pos + d - 1) >> 3] & mask[(pos + d - 1) & 7])) ||
           (tmp + d > 0 && !!(t[(tmp + d) >> 3] & mask[(tmp + d) & 7]) &&
            !!!(t[(tmp + d - 1) >> 3] & mask[(tmp + d - 1) & 7]))))
        break;
    }
    if (diff) name++, tmp = pos;
    SA[n1 + ((pos - (pos & 1)) >> 1)] = name - 1;
  }
  int *s1 = SA + n - n1;
  for (int i = n - 1, j = n - 1; i >= n1; i--)
    if (SA[i] >= 0) SA[j--] = SA[i];
  if (name < n1)
    SA_IS((unsigned char *)s1, SA, n1, name - 1, sizeof(int));
  else
    for (int i = 0; i < int(n1); ++i) SA[s1[i]] = i;
  getBuckets(s, bkt, n, K, cs);
  for (int i = 1, j = 0; i < n; i++)
    if ((i > 0 && !!(t[(i) >> 3] & mask[(i)&7]) &&
         !!!(t[(i - 1) >> 3] & mask[(i - 1) & 7])))
      s1[j++] = i;
  for (int i = 0; i < int(n1); ++i) SA[i] = s1[SA[i]];
  fill(SA + n1, SA + n, -1);
  for (int i = int(n1 - 1); i >= int(0); --i) {
    int tmp = SA[i];
    SA[i] = -1,
    SA[--bkt[(cs == sizeof(int) ? ((int *)s)[tmp]
                                : ((unsigned char *)s)[tmp])]] = tmp;
  }
  induceSAl(t, SA, s, bkt, n, K, cs);
  induceSAs(t, SA, s, bkt, n, K, cs);
}
const int maxn = 1000001;
int n, sa[maxn];
bool contain(string S, int *sa, string T) {
  int a = 0, b = S.length();
  while (b - a > 1) {
    int c = (a + b) / 2;
    if (S.compare(sa[c], T.length(), T) < 0)
      a = c;
    else
      b = c;
  }
  return S.compare(sa[b], T.length(), T) == 0;
}
char a[maxn], b[maxn];
int main(void) {
  int q;
  scanf("%s", a);
  string s = string(a);
  SA_IS((unsigned char *)s.c_str(), sa, s.size() + 1);
  scanf("%d", &q);
  while (q--) {
    scanf("%s", b);
    if (contain(s, sa, string(b)))
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}
