#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;
}
vector<int> build_kmp(const string &s) {
  int n = s.size();
  vector<int> a(n + 1, -1);
  int j = -1;
  for (int i = (int)(0); i < (int)(n); i++) {
    while (j >= 0 && s[i] != s[j]) j = a[j];
    j++;
    if (s[i + 1] == s[j])
      a[i + 1] = a[j];
    else
      a[i + 1] = j;
  }
  return a;
}
bool kmp_match(const string &txt, const string &pat, const vector<int> &skip) {
  int n = txt.size();
  int m = pat.size();
  vector<int> ret;
  int j = 0;
  for (int i = (int)(0); i < (int)(n); i++) {
    while (j > -1 && txt[i] != pat[j]) j = skip[j];
    j++;
    if (j == m) {
      return true;
    }
  }
  return false;
}
int main() {
  string t;
  int q;
  cin >> t >> q;
  for (int _ = (int)(0); _ < (int)(q); _++) {
    string p;
    cin >> p;
    auto skip = build_kmp(p);
    cout << kmp_match(t, p, skip) << endl;
  }
  return 0;
}
