#include <bits/stdc++.h>
int min(int a, int b) {
  if (a > b) return b;
  return a;
}
int max(int a, int b) {
  if (a > b) return a;
  return b;
}
int tblnum[30];
int tbllow[30];
int tblup[30];
void maketable(char P[]) {
  int i;
  int PL = strlen(P);
  for (i = 0; i < 30; i++) {
    tblnum[i] = INT_MAX;
    tbllow[i] = INT_MAX;
    tblup[i] = INT_MAX;
  }
  for (i = 0; i < PL; i++) {
    if (isdigit(P[i]))
      tblnum[P[i] - '0'] = min(tblnum[P[i] - '0'], PL - 1 - i);
    else if (islower(P[i]))
      tbllow[P[i] - 'a'] = min(tbllow[P[i] - 'a'], PL - 1 - i);
    else if (isupper(P[i]))
      tblup[P[i] - 'A'] = min(tblup[P[i] - 'A'], PL - 1 - i);
  }
  for (i = 0; i < 30; i++) {
    if (tblnum[i] == INT_MAX) tblnum[i] = PL;
    if (tbllow[i] == INT_MAX) tbllow[i] = PL;
    if (tblup[i] == INT_MAX) tblup[i] = PL;
  }
  return;
}
int WidthCheck(char c) {
  if (isdigit(c)) return tblnum[c - '0'];
  if (islower(c)) return tbllow[c - 'a'];
  if (isupper(c)) return tblup[c - 'A'];
}
int main() {
  char T[1000001];
  char P[10001];
  int i, TL, PL, n;
  int end;
  int width;
  int R;
  scanf("%s", T);
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", P);
    maketable(P);
    TL = strlen(T);
    PL = strlen(P);
    end = PL - 1;
    while (end < TL) {
      for (i = end; i > end - PL; i--) {
        if (P[PL - 1 - (end - i)] != T[i]) {
          width = WidthCheck(T[i]);
          end = max(end + 1, i + width);
          break;
        }
        if (i == end - PL + 1) {
          printf("1\n");
          break;
        }
      }
      if (i == end - PL + 1) break;
    }
    if (i != end - PL + 1 && end >= TL) printf("0\n");
  }
  return 0;
}
