#include <bits/stdc++.h>
using namespace std;
constexpr int kAlphabetSize = 37;
int ValueOf(char ch) {
  if (ch == '$') return 0;
  if ('0' <= ch && ch <= '9') return 1 + ch - '0';
  if ('a' <= ch && ch <= 'z') return 11 + ch - 'a';
  cout << "Unexpected character!" << endl;
  exit(1);
  return -1;
}
vector<int> SortCyclicShifts(string &A) {
  int n = A.size();
  vector<int> p(n), c(n), psecond(n), cnext(n), count(max(n, kAlphabetSize));
  for (int i = 0; i < n; ++i) ++count[ValueOf(A[i])];
  for (int i = 1; i < count.size(); ++i) count[i] += count[i - 1];
  for (int i = n - 1; i >= 0; --i) p[--count[ValueOf(A[i])]] = i;
  int num_classes = 1;
  for (int i = 1; i < n; ++i) {
    if (A[p[i]] != A[p[i - 1]]) {
      c[p[i]] = num_classes;
      ++num_classes;
    } else {
      c[p[i]] = c[p[i - 1]];
    }
  }
  for (int h = 0; (1 << h) < n; ++h) {
    for (int i = 0; i < n; ++i) {
      psecond[i] = p[i] - (1 << h);
      if (psecond[i] < 0) psecond[i] += n;
    }
    fill_n(begin(count), num_classes, 0);
    for (int i = 0; i < n; ++i) ++count[c[i]];
    for (int i = 1; i < num_classes; ++i) count[i] += count[i - 1];
    for (int i = n - 1; i >= 0; --i) p[--count[c[psecond[i]]]] = psecond[i];
    num_classes = 1;
    cnext[p[0]] = 0;
    for (int i = 1; i < n; ++i) {
      if (c[p[i]] == c[p[i - 1]] &&
          c[p[i] + (1 << h) % n] == c[p[i - 1] + (1 << h) % n]) {
        cnext[p[i]] = cnext[p[i - 1]];
      } else {
        cnext[p[i]] = cnext[p[i - 1]] + 1;
        ++num_classes;
      }
    }
    c.swap(cnext);
  }
  return p;
}
int main() {
  string T;
  cin >> T;
  T.push_back('$');
  auto suf = SortCyclicShifts(T);
  int q;
  cin >> q;
  string P;
  for (int i = 0; i < q; ++i) {
    cin >> P;
    auto res =
        lower_bound(begin(suf), end(suf), P, [&T](int x, const string &P) {
          string cmp = T.substr(x, P.size());
          return cmp < P;
        });
    cout << (P == T.substr(*res, P.size())) << endl;
  }
}
