#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
class SA_IS {
 private:
  using byte = unsigned char;
  byte mask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  void getBuckets(byte *s, int *bkt, int n, int K, int cs, bool end = true) {
    fill(bkt, bkt + K + 1, 0);
    for (int i = 0; i < n; i++) {
      bkt[(cs == sizeof(int) ? ((int *)s)[i] : ((byte *)s)[i])]++;
    }
    for (int i = 0, tmp = 0; i < K + 1; i++) {
      tmp += bkt[i];
      bkt[i] = end ? tmp : tmp - bkt[i];
    }
  }
  void induceSAl(byte *t, byte *s, int *bkt, int n, int K, int cs) {
    getBuckets(s, bkt, n, K, cs, false);
    for (int i = 0; i < 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]
                                  : ((byte *)s)[sa[i] - 1])]++] = sa[i] - 1;
      }
    }
  }
  void induceSAs(byte *t, byte *s, int *bkt, int n, int K, int cs) {
    getBuckets(s, bkt, n, K, cs, true);
    for (int i = n - 1; i >= 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]
                                    : ((byte *)s)[sa[i] - 1])]] = sa[i] - 1;
      }
    }
  }
  void solve(byte *s, int n, int K = 128, int cs = 1) {
    byte 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 = n - 3; i >= 0; i--) {
      t[(i) >> 3] =
          (((cs == sizeof(int) ? ((int *)s)[i] : ((byte *)s)[i]) <
                (cs == sizeof(int) ? ((int *)s)[i + 1] : ((byte *)s)[i + 1]) ||
            ((cs == sizeof(int) ? ((int *)s)[i] : ((byte *)s)[i]) ==
                 (cs == sizeof(int) ? ((int *)s)[i + 1] : ((byte *)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 = 1; i < 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] : ((byte *)s)[i])]] = i;
      }
    }
    induceSAl(t, s, bkt, n, K, cs);
    induceSAs(t, s, bkt, n, K, cs);
    for (int i = 0; i < 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 < n1; i++) {
      int pos = sa[i], diff = false;
      for (int d = 0; d < n && !diff; d++) {
        diff =
            (cs == sizeof(int) ? ((int *)s)[pos + d] : ((byte *)s)[pos + d]) !=
                (cs == sizeof(int) ? ((int *)s)[tmp + d]
                                   : ((byte *)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) {
      solve((byte *)s1, n1, name - 1, sizeof(int));
    } else {
      for (int i = 0; i < 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 < n1; i++) {
      sa[i] = s1[sa[i]];
    }
    fill(sa + n1, sa + n, -1);
    for (int i = n1 - 1; i >= 0; i--) {
      int tmp = sa[i];
      sa[i] = -1,
      sa[--bkt[(cs == sizeof(int) ? ((int *)s)[tmp] : ((byte *)s)[tmp])]] = tmp;
    }
    induceSAl(t, s, bkt, n, K, cs);
    induceSAs(t, s, bkt, n, K, cs);
  }

 public:
  bool contain(const string &T) {
    string SS = string((char *)S);
    int a = 0, b = sz;
    while (b - a > 1) {
      int c = (a + b) / 2;
      if (SS.compare(sa[c], T.length(), T) < 0) {
        a = c;
      } else {
        b = c;
      }
    }
    return SS.compare(sa[b], T.length(), T) == 0;
  }
  byte *S;
  int sz;
  int *sa;
  SA_IS(string &arg) {
    sz = (int)arg.size();
    sa = new int[sz + 1];
    S = (byte *)arg.c_str();
    solve(S, sz + 1);
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  SA_IS sa(s);
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    string t;
    cin >> t;
    cout << sa.contain(t) << "\n";
  }
  return 0;
}
