#include <bits/stdc++.h>
void Search(char *P, int Plen, char *T, int Tlen, int *MoveP) {
  int i, initMP[256], cnt = 0, j, flg, nflg = 0;
  for (i = 1; i <= Plen; i++) {
    if (i - 1 < MoveP[(unsigned int)P[Plen - i]]) {
      MoveP[(unsigned int)P[Plen - i]] = i - 1;
      initMP[cnt] = (unsigned int)P[Plen - i];
      cnt++;
    }
  }
  for (i = 0; i <= Tlen - Plen; i++) {
    flg = 0;
    if (T[Plen + i - 1] == P[Plen - 1]) {
      for (j = 1; j <= Plen; j++) {
        if (T[Plen + i - j] != P[Plen - j]) {
          flg = 1;
          i += MoveP[(unsigned int)P[Plen - j]];
          break;
        }
      }
      if (flg == 0) {
        printf("1\n");
        nflg = 1;
        break;
      }
    }
  }
  if (nflg == 0) {
    printf("0\n");
  }
  for (i = 0; i < cnt; i++) {
    MoveP[initMP[i]] = 256;
  }
}
int main() {
  int n, i, j, Tlen, Plen, MoveP[256];
  char T[1000000], P[1000];
  scanf("%s", T);
  scanf("%d", &n);
  Tlen = strlen(T);
  for (i = 0; i < 256; i++) {
    MoveP[i] = 256;
  }
  for (i = 0; i < n; i++) {
    scanf("%s", P);
    Plen = strlen(P);
    Search(P, Plen, T, Tlen, MoveP);
  }
}
