#include <bits/stdc++.h>
using namespace std;
struct SuffixArray {
  string s;
  size_t n;
  vector<size_t> sarray, rank;
  SuffixArray(string s) : s(s), n(s.length()) {
    sarray.assign(n + 1, 0);
    rank.assign(n + 1, 0);
    for (size_t i = 0; i <= n; ++i) {
      sarray[i] = i;
      rank[i] = i < n ? s[i] : -1;
    }
    vector<size_t> tmp(n + 1);
    for (size_t k = 1; k <= n; k <<= 1) {
      auto comp = [&, k](size_t i, size_t j) -> bool {
        if (rank[i] != rank[j]) return rank[i] < rank[j];
        int ri = i + k <= n ? rank[i + k] : -1;
        int rj = j + k <= n ? rank[j + k] : -1;
        return ri < rj;
      };
      sort(sarray.begin(), sarray.end(), comp);
      for (size_t i = 1; i <= n; ++i)
        tmp[sarray[i]] = tmp[sarray[i - 1]] + comp(sarray[i - 1], sarray[i]);
      for (size_t i = 0; i <= n; ++i) rank[i] = tmp[i];
    }
  }
  bool is_substr(string t) {
    size_t lb = -1, ub = s.length();
    while (ub - lb > 1) {
      size_t mid = (lb + ub) / 2;
      (s.compare(sarray[mid], t.length(), t) < 0 ? lb : ub) = mid;
    }
    return !s.compare(sarray[ub], t.length(), t);
  }
};
int main() {
  char buf[1 << 20];
  scanf("%s", buf);
  string T(buf);
  SuffixArray sa(T);
  size_t Q;
  scanf("%zu", &Q);
  for (size_t i = 0; i < Q; ++i) {
    scanf("%s", buf);
    string P(buf);
    printf("%d\n", sa.is_substr(P));
  }
  return 0;
}
