#include <bits/stdc++.h>
using namespace std;
void _dbg(string) { cout << endl; }
template <class H, class... T>
void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cout << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
class SuffixArray {
 public:
  string &s;
  vector<int> sa;
  int n;
  SuffixArray(string &str) : s(str) { n = s.size(); }
  void construct_sa() {
    sa.resize(n + 1);
    vector<int> rank(n + 1);
    for (int i = (int)(0); i < (int)(n + 1); i++) {
      sa[i] = i;
      rank[i] = (i < n) ? s[i] : (-1);
    }
    for (int k = 1; k <= n; k *= 2) {
      function<bool(int, int)> comp = [&](int i, int j) {
        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((sa).begin(), (sa).end(), comp);
      vector<int> tmp(n + 1, 0);
      tmp[sa[0]] = 0;
      for (int i = (int)(1); i < (int)(n + 1); i++) {
        tmp[sa[i]] = tmp[sa[i - 1]];
        if (comp(sa[i - 1], sa[i])) tmp[sa[i]]++;
      }
      swap(tmp, rank);
    }
  }
  bool contain(const string &t) {
    int m = t.size();
    int l = 0, r = n;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (s.compare(sa[mid], m, t) < 0)
        l = mid;
      else
        r = mid;
    }
    return s.compare(sa[r], m, t) == 0;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string t;
  int q;
  cin >> t >> q;
  SuffixArray sa(t);
  sa.construct_sa();
  for (int _ = (int)(0); _ < (int)(q); _++) {
    string p;
    cin >> p;
    cout << sa.contain(p) << endl;
  }
  return 0;
}
