#include <bits/stdc++.h>
char T[1000001], P[10001];
int n, m;
int F[10001];
void Prefix_Table(char P[], int m) {
  int i = 1, j = 0;
  F[0] = 0;
  while (i < m) {
    if (P[i] == P[j]) {
      F[i] = j + 1;
      i++;
      j++;
    } else if (j > 0)
      j = F[j - 1];
    else {
      F[i] = 0;
      i++;
    }
  }
}
int KMP(char T[], int n, char P[], int m) {
  int i = 0, j = 0;
  Prefix_Table(P, m);
  while (i < n) {
    if (T[i] == P[j]) {
      if (j == m - 1)
        return 1;
      else {
        i++;
        j++;
      }
    } else if (j > 0)
      j = F[j - 1];
    else
      i++;
  }
  return 0;
}
int main() {
  int num;
  scanf("%s", T);
  scanf("%d", &num);
  for (int i = 1; i <= num; i++) {
    scanf("%s", P);
    n = strlen(T);
    m = strlen(P);
    if (KMP(T, n, P, m))
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}
