#include <bits/stdc++.h>
using namespace std;
struct suffix_array {
  long long n;
  vector<long long> x;
  suffix_array(const char *s) : n(strlen(s)), x(n) {
    vector<long long> r(n), t(n);
    for (long long i = 0; i < n; ++i) r[x[i] = i] = s[i];
    for (long long h = 1; t[n - 1] != n - 1; h *= 2) {
      auto cmp = [&](long long i, long long j) {
        if (r[i] != r[j]) return r[i] < r[j];
        return i + h < n && j + h < n ? r[i + h] < r[j + h] : i > j;
      };
      sort(x.begin(), x.end(), cmp);
      for (long long i = 0; i + 1 < n; ++i)
        t[i + 1] = t[i] + cmp(x[i], x[i + 1]);
      for (long long i = 0; i < n; ++i) r[x[i]] = t[i];
    }
  }
  long long operator[](long long i) const { return x[i]; }
};
signed main() {
  ios::sync_with_stdio(false);
  string T;
  cin >> T;
  long long Q;
  cin >> Q;
  suffix_array sary(T.c_str());
  while (Q--) {
    string P;
    cin >> P;
    long long lb = -1, ub = T.size() - 1;
    while (ub - lb > 1) {
      long long mid = (lb + ub) / 2;
      bool flag = sary[mid] + (long long)P.size() <= (long long)T.size();
      for (long long i = 0;
           i < (long long)P.size() && sary[mid] + i < (long long)T.size();
           i++) {
        if (T[sary[mid] + i] < P[i]) flag = false;
      }
      if (flag)
        ub = mid;
      else
        lb = mid;
    }
    bool flag = sary[ub] + (long long)P.size() <= (long long)T.size();
    if (flag) {
      for (long long i = 0; i < (long long)(P.size()); ++i) {
        if (T[sary[ub] + i] != P[i]) flag = false;
      }
      cout << (long long)flag << endl;
    } else {
      cout << 0 << endl;
    }
  }
}
