#include <bits/stdc++.h>
using namespace std;
string T;
int *A, *lev, *new_lev;
int k, n;
bool cmp_ex(int i, int j) {
  if (T[i] != T[j]) {
    return lev[i] < lev[j];
  }
  return (i + k <= n ? lev[i + k] : -1) < (j + k <= n ? lev[j + k] : -1);
}
int main() {
  int i;
  cin >> T;
  n = T.size();
  A = new int[n + 1];
  lev = new int[n + 1];
  new_lev = new int[n + 1];
  for (i = 0; i < n; i++) {
    A[i] = i;
    lev[i] = T[i];
  }
  A[n] = n, lev[n] = -1;
  k = 1;
  while (1) {
    sort(A, A + n + 1, cmp_ex);
    new_lev[A[0]] = 0;
    for (i = 0; i < n; i++) {
      new_lev[A[i + 1]] = new_lev[A[i]] + (cmp_ex(A[i], A[i + 1]) ? 1 : 0);
    }
    if (new_lev[A[n]] == n) break;
    for (i = 0; i <= n; i++) lev[i] = new_lev[i];
    k <<= 1;
  };
  int q;
  scanf("%d", &q);
  string P;
  int lp, left, right, mid, crit;
  bool exist;
  while (q) {
    cin >> P;
    lp = P.size();
    left = 1;
    right = n;
    exist = false;
    while (left <= right) {
      if (lp > n) break;
      mid = (left + right) / 2;
      crit = T.compare(A[mid], lp, P);
      if (crit > 0) {
        right = mid - 1;
      } else if (crit < 0) {
        left = mid + 1;
      } else {
        exist = true;
        break;
      }
    };
    if (exist) {
      printf("1\n");
    } else {
      printf("0\n");
    }
    q--;
  };
  return 0;
}
