#include <bits/stdc++.h>
using namespace std;
vector<int> build_fail(const char *s) {
  int N = strlen(s);
  vector<int> fail(N + 1);
  int j = fail[0] = -1;
  for (int i = 1; i <= N; i++) {
    while (j >= 0 && s[j] != s[i - 1]) j = fail[j];
    fail[i] = ++j;
  }
  return fail;
}
int match(const char *t, const char *p, const vector<int> &fail) {
  int n = strlen(t), m = strlen(p), res = 0;
  for (int i = 0, k = 0; i < n; i++) {
    while (k >= 0 && p[k] != t[i]) k = fail[k];
    if (++k >= m) {
      res++;
      k = fail[k];
    }
  }
  return res;
}
int main() {
  int Q, M;
  char T[1000001], P[1001];
  scanf("%s %d", T, &Q);
  vector<int> fail = build_fail(T);
  while (Q--) {
    scanf("%s", P);
    M = strlen(P);
    cout << (match(T, P, fail) == M + 1) << endl;
  }
  return 0;
}
