#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000000 + 7;
const long long hmod1 = 999999937;
const long long hmod2 = 1000000000 + 9;
const long long INF = 1 << 30;
const long long dx4[4] = {1, 0, -1, 0};
const long long dy4[4] = {0, 1, 0, -1};
const long long dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const long long dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
struct SuffixArray {
  long long n, k;
  string text;
  vector<long long> sa;
  vector<long long> rank;
  vector<long long> lcp;
  SuffixArray(const string &s)
      : text(s), n(s.size()), sa(n + 1), rank(n + 1), lcp(n) {}
  bool comp(long long i, long long j) {
    if (rank[i] != rank[j]) return rank[i] < rank[j];
    long long ri = i + k <= n ? rank[i + k] : -1;
    long long rj = j + k <= n ? rank[j + k] : -1;
    return ri < rj;
  }
  void construct_sa() {
    for (long long i = 0; i <= n; i++) {
      sa[i] = i;
      rank[i] = i < n ? text[i] : -1;
    }
    for (k = 1; k <= n; k *= 2) {
      sort(sa.begin(), sa.end(),
           [&](const long long &i, const long long &j) { return comp(i, j); });
      vector<long long> tmp(n + 1);
      tmp[sa[0]] = 0;
      for (long long i = 1; i <= n; i++) {
        tmp[sa[i]] = tmp[sa[i - 1]] + (comp(sa[i - 1], sa[i]) ? 1 : 0);
      }
      for (long long i = 0; i <= n; i++) {
        rank[i] = tmp[i];
      }
    }
  }
  void construct_lcp() {
    long long h = 0;
    lcp[0] = 0;
    for (long long i = 0; i < n; i++) {
      long long j = sa[rank[i] - 1];
      if (h > 0) h--;
      for (; j + h < n && i + h < n; h++) {
        if (text[j + h] != text[i + h]) break;
      }
      lcp[rank[i] - 1] = h;
    }
  }
  long long low_bd(const string &pt) {
    long long l = 0, r = n + 1;
    while (r - l > 1) {
      long long m = (r + l) / 2;
      long long val = text.compare(sa[m], pt.length(), pt);
      if (val < 0)
        l = m;
      else
        r = m;
    }
    return r;
  }
  long long up_bd(const string &pt) {
    long long l = 1, r = n + 1;
    while (r - l > 1) {
      long long m = (r + l) / 2;
      long long val = text.compare(sa[m], pt.length(), pt);
      if (val <= 0)
        l = m;
      else
        r = m;
    }
    return r;
  }
  bool match(const string &pt) {
    long long idx = low_bd(pt);
    if (idx == sa.size()) return false;
    return text.compare(sa[idx], pt.length(), pt) == 0 ? true : false;
  }
  long long count(const string &pt) {
    long long l_idx = low_bd(pt);
    if (l_idx == sa.size()) return 0;
    if (text.compare(sa[l_idx], pt.length(), pt) != 0) return 0;
    long long r_idx = up_bd(pt);
    return r_idx - l_idx;
  }
};
string t;
long long q;
string p[1000];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> t;
  cin >> q;
  for (long long i = 0; i < (q); i++) cin >> p[i];
  SuffixArray suf(t);
  suf.construct_sa();
  for (long long i = 0; i < (q); i++) {
    cout << suf.match(p[i]) << endl;
  }
}
