#include <bits/stdc++.h>
using namespace std;
int n;
char s[1000001];
int q;
char t[1001];
int a[1000000];
int b[1000000];
inline int comp(char* s, int x, char* t, int y) {
  int i = 0;
  while (i < x && i < y) {
    if (s[i] > t[i]) {
      return 1;
    } else if (s[i] < t[i]) {
      return -1;
    }
    ++i;
  }
  return x - y;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  vector<pair<int, int> > v;
  for (int i = 0; i < (n); ++i) {
    v.push_back(pair<int, int>(s[i], i));
  }
  sort(v.begin(), v.end());
  a[v[0].second] = 0;
  for (int i = 0; i < (n - 1); ++i) {
    a[v[i + 1].second] = a[v[i].second] + (v[i].first != v[i + 1].first);
  }
  for (int i = 0; i < (20); ++i) {
    vector<pair<pair<int, int>, int> > v;
    for (int j = 0; j < (n); ++j) {
      if (j + (1 << i) < n) {
        v.push_back(pair<pair<int, int>, int>(
            pair<int, int>(a[j], a[j + (1 << i)]), j));
      } else {
        v.push_back(pair<pair<int, int>, int>(pair<int, int>(a[j], -1), j));
      }
    }
    sort(v.begin(), v.end());
    a[v[0].second] = 0;
    for (int j = 0; j < (n - 1); ++j) {
      a[v[j + 1].second] = a[v[j].second] + (v[j].first != v[j + 1].first);
    }
  }
  for (int i = 0; i < (n); ++i) {
    b[a[i]] = i;
  }
  scanf("%d", &q);
  for (int i = 0; i < (q); ++i) {
    scanf("%s", t);
    int k = strlen(t);
    int l = 0, r = n;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (comp(s + b[m], min(k, n - b[m]), t, k) <= 0) {
        l = m;
      } else {
        r = m;
      }
    }
    printf("%d\n", comp(s + b[l], min(k, n - b[l]), t, k) == 0);
  }
}
