#include <bits/stdc++.h>
int main() {
  char *T = (char *)malloc(1000000 + 1);
  if (T == NULL) {
    printf("memory shortage.\n");
    return 1;
  }
  scanf("%s", T);
  int q = 0;
  scanf("%d", &q);
  char P[1000 + 1];
  for (int i = 0; i < q; ++i) {
    scanf("%s", P);
    printf("%d\n", strstr(T, P) != NULL ? 1 : 0);
  }
  free(T);
  return 0;
}
