#include <bits/stdc++.h>
using namespace std;
int Q;
string s;
vector<unsigned long long> p, h;
unsigned long long gethash(int l, int r) { return h[r] - h[l] * p[r - l]; }
int lcp(int x, int y) {
  int l = 0, r = min(s.size() - x, s.size() - y) + 1;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (gethash(x, x + m) == gethash(y, y + m))
      l = m;
    else
      r = m;
  }
  return l;
}
bool compare_sa(int i, int j) {
  int k = lcp(i, j);
  if (i + k >= s.size()) return true;
  if (j + k >= s.size()) return false;
  return s[i + k] <= s[j + k];
}
int main() {
  cin >> s >> Q;
  vector<int> l(Q + 2);
  l[1] = s.size();
  for (int i = 0; i < Q; i++) {
    string t;
    cin >> t;
    s += t;
    l[i + 2] = l[i + 1] + t.size();
  }
  p.resize(s.size() + 1);
  p[0] = 1;
  h.resize(s.size() + 1);
  for (int i = 0; i < s.size(); i++) {
    p[i + 1] = p[i] * 257;
    h[i + 1] = h[i] * 257 + s[i];
  }
  vector<int> sa(s.size());
  iota(sa.begin(), sa.end(), 0);
  sort(sa.begin(), sa.end(), compare_sa);
  vector<int> sa_inv(s.size());
  for (int i = 0; i < s.size(); i++) sa_inv[sa[i]] = i;
  vector<int> v;
  for (int i = 0; i < s.size(); i++) {
    if (sa[i] < l[1]) v.push_back(i);
  }
  for (int i = 0; i < Q; i++) {
    int w = sa_inv[l[i + 1]];
    int ptr = lower_bound(v.begin(), v.end(), w) - v.begin();
    bool flag = false;
    for (int j = -1; j <= 0; j++) {
      int pos = ptr + j;
      if (0 <= pos && pos < v.size()) {
        if (lcp(sa[v[pos]], l[i + 1]) >= l[i + 2] - l[i + 1]) flag = true;
      }
    }
    cout << flag << endl;
  }
  return 0;
}
