#include <bits/stdc++.h>
const unsigned long long B = 100000007;
bool contain(char *a, char *b) {
  int al = strlen(a), bl = strlen(b);
  if (al > bl) return false;
  unsigned long long t = 1;
  for (int i = 0; i < al; i++) t *= B;
  unsigned long long ah = 0, bh = 0;
  for (int i = 0; i < al; i++) ah = ah * B + a[i];
  for (int i = 0; i < al; i++) bh = bh * B + b[i];
  for (int i = 0; i + al <= bl; i++) {
    if (ah == bh) return true;
    if (i + al < bl) bh = bh * B + b[i + al] - b[i] * t;
  }
  return false;
}
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", contain(P, T) ? 1 : 0);
  }
  free(T);
  return 0;
}
