#include <bits/stdc++.h>
using namespace std;
class SuffixArray {
 private:
  int n, k;
  string s;
  vector<int> rank;
  vector<int> tmp;
  bool compare_sa(const int &i, const int &j) {
    if (rank[i] != rank[j])
      return rank[i] < rank[j];
    else {
      int ri = i + k <= n ? rank[i + k] : -1;
      int rj = j + k <= n ? rank[j + k] : -1;
      return ri < rj;
    }
  }
  void construct_sa() {
    for (int i = 0; i <= n; i++) {
      sa[i] = i;
      rank[i] = i < n ? s[i] : -1;
    }
    for (k = 1; k <= n; k *= 2) {
      sort(sa.begin(), sa.end(), *this);
      tmp[sa[0]] = 0;
      for (int i = 1; i <= n; i++)
        tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
      for (int i = 0; i <= n; i++) rank[i] = tmp[i];
    }
  }

 public:
  vector<int> sa;
  bool operator()(const int &i, const int &j) const {
    if (rank[i] != rank[j])
      return rank[i] < rank[j];
    else {
      int ri = i + k <= n ? rank[i + k] : -1;
      int rj = j + k <= n ? rank[j + k] : -1;
      return ri < rj;
    }
  }
  SuffixArray(string s) : s(s) {
    n = s.size();
    rank.resize(n + 1);
    tmp.resize(n + 1);
    sa.resize(n + 1);
    construct_sa();
  }
  bool contain(string t) {
    int l = 0, r = n;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (s.compare(sa[m], t.size(), t) < 0)
        l = m;
      else
        r = m;
    }
    return s.compare(sa[r], t.size(), t) == 0;
  }
};
int main() {
  string s, t;
  cin >> s;
  auto sa = SuffixArray(s);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t;
    cout << sa.contain(t) << endl;
  }
  return 0;
}
