#include <bits/stdc++.h>
int main() {
  int i;
  int j;
  int num;
  int str_length;
  int cmp_length;
  char *str;
  char *cmp;
  str = (char *)malloc(sizeof(char) * 1000000);
  cmp = (char *)malloc(sizeof(char) * 1000);
  scanf("%s", str);
  str_length = strlen(str);
  scanf("%d", &num);
  for (i = 0; i < num; i++) {
    cmp = (char *)malloc(sizeof(char) * 1000);
    scanf("%s", cmp);
    cmp_length = strlen(cmp);
    for (j = 0; j < str_length; j++) {
      if (strncmp(str + j, cmp, cmp_length) == 0) {
        printf("1\n");
        break;
      }
      if (j == str_length - 1) {
        printf("0\n");
      }
    }
    free(cmp);
  }
  return 0;
}
