#include <bits/stdc++.h>
using namespace std;
int main() {
  char T[1000000];
  scanf("%s", T);
  int len_T = 0;
  while (T[len_T]) {
    len_T++;
  };
  char P[1000];
  int len_P;
  long long *has_T, *has_P;
  has_T = new long long[len_T];
  has_P = new long long[10001];
  long long last_has;
  long long h;
  int i;
  h = 0;
  for (i = 0; i < len_T; i++) {
    h = (h * 1995455101 + T[i]) % 1995455447;
    has_T[i] = h;
  }
  long long pow[1001];
  pow[0] = 1;
  for (i = 1; i < 1001; i++) {
    pow[i] = (pow[i - 1] * 1995455101) % 1995455447;
  }
  int q;
  scanf("%d", &q);
  while (q) {
    scanf("%s", P);
    len_P = 0;
    while (P[len_P]) {
      len_P++;
    };
    h = 0;
    for (i = 0; i < len_P; i++) {
      h = (h * 1995455101 + P[i]) % 1995455447;
      has_P[i] = h;
    }
    last_has = has_P[len_P - 1];
    for (i = len_P - 1; i < len_T; i++) {
      if (has_T[i] ==
          ((i >= len_P ? has_T[i - len_P] : 0) * pow[len_P] + last_has) %
              1995455447) {
        printf("%d\n", 1);
        break;
      }
    }
    if (i == len_T) {
      printf("%d\n", 0);
    }
    q--;
  };
  return 0;
}
