#include <bits/stdc++.h>
int mischarSearch(char*, char*);
int* initSkip(char*);
int myIndex(char);
int main() {
  char T[1000001];
  char P[1001];
  int* pos;
  int i;
  int Q;
  scanf("%s", T);
  scanf("%d", &Q);
  for (i = 0; i < Q; ++i) {
    scanf("%s", P);
    printf("%d\n", mischarSearch(T, P));
  }
  return 0;
}
int mischarSearch(char* T, char* P) {
  int i, j, t;
  int M = strlen(P);
  int N = strlen(T);
  int* skip;
  skip = initSkip(P);
  for (i = M - 1, j = M - 1; j >= 0; i--, j--) {
    while (T[i] != P[j]) {
      t = skip[myIndex(T[i])];
      i += (M - j > t) ? M - j : t;
      if (i >= N) {
        return 0;
      }
      j = M - 1;
    }
  }
  return 1;
}
int* initSkip(char* P) {
  int i;
  int M = strlen(P);
  int* skip;
  skip = (int*)malloc(sizeof(int) * 64);
  for (i = 0; i < 64; ++i) {
    skip[i] = M;
  }
  for (i = 0; i < M; ++i) {
    skip[myIndex(P[i])] = M - i - 1;
  }
  return skip;
}
int myIndex(char c) {
  if ('a' <= c && c <= 'z') {
    return c - 'a' + 1;
  } else if ('A' <= c && c <= 'Z') {
    return c - 'A' + 27;
  } else if ('0' <= c && c <= '9') {
    return c - '0' + 53;
  } else {
    return 0;
  }
}
