#include <bits/stdc++.h>
int t[10000000], p[100000];
int check(int i, int q) {
  int j;
  for (j = 1; j < q - 1; j++)
    if (t[j + i] != p[j]) return 0;
  return 1;
}
int main() {
  int i, j, l = 0, q = 0, n, count = 0;
  while ((t[l++] = getchar()) != '\n') {
  }
  scanf("%d ", &n);
  for (j = 0; j < n; j++) {
    count = 0;
    q = 0;
    while ((p[q++] = getchar()) != '\n') {
    }
    for (i = 0; i < l - q + 1; i++) {
      if (t[i] != p[0] || t[i + q - 2] != p[q - 2])
        continue;
      else if (check(i, q - 1)) {
        count++;
        break;
      }
    }
    if (count > 0)
      puts("1");
    else
      puts("0");
  }
  return 0;
}
