#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.tie(0);
  ios::sync_with_stdio(false);
  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 < 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;
    }
  }
  sort(sa.begin(), sa.end(),
       [](long long a, long long b) { return rnk[a] < rnk[b]; });
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> p;
    auto from = sa.begin();
    auto to = sa.end();
    for (long long i = 0; i < p.size(); i++) {
      from = lower_bound(from, to, p[i], [i](long long x, char c) {
        if (x + i >= t.size()) return false;
        return t[x + i] < c;
      });
      to = lower_bound(from, to, p[i], [i](long long x, char c) {
        if (x + i >= t.size()) return false;
        return t[x + i] < c + 1;
      });
    }
    if (to - from > 0)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
