#include <bits/stdc++.h>
using namespace std;
string t;
string p;
long long q;
vector<long long> sa;
vector<long long> tmp;
vector<pair<long long, long long> > rnk;
int main() {
  cin >> t;
  sa = vector<long long>(t.size());
  rnk = vector<pair<long long, long long> >(t.size());
  tmp = vector<long long>(t.size());
  for (long long i = 0; i < t.size(); i++) sa[i] = i;
  for (long long i = 0; i < t.size(); i++) get<0>(rnk[i]) = t[i];
  for (long long k = 1; k < 2 * t.size(); k *= 2) {
    sort(sa.begin(), sa.end(),
         [](long long a, long long b) { return rnk[a] < rnk[b]; });
    for (long long i = 1; i < sa.size(); i++) {
      tmp[sa[i]] = tmp[sa[i - 1]];
      if (rnk[sa[i]] != rnk[sa[i - 1]]) tmp[sa[i]]++;
    }
    for (long long i = 0; i < sa.size(); i++) {
      get<0>(rnk[sa[i]]) = tmp[sa[i]];
    }
    for (long long i = 0; i < sa.size(); i++) {
      if (sa[i] + k < t.size())
        get<1>(rnk[sa[i]]) = get<0>(rnk[sa[i] + k]);
      else
        get<1>(rnk[sa[i]]) = -1;
    }
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> p;
    long long lwrbnd = *lower_bound(
        sa.begin(), sa.end(), p,
        [](long long a, string s) { return t.compare(a, s.size(), s) < 0; });
    if (t.compare(lwrbnd, p.size(), p) == 0)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
