#include <bits/stdc++.h>
using namespace std;
int n, sa[1 << 20], r[1 << 20], tmp[1 << 20];
char s[1 << 20];
int k;
bool comp(int i, int j) {
  if (r[i] != r[j])
    return r[i] < r[j];
  else {
    int ri = i + k <= n ? r[i + k] : -1;
    int rj = j + k <= n ? r[j + k] : -1;
    return ri < rj;
  }
}
void construct() {
  n = strlen(s);
  for (int i = 0; i <= n; i++) {
    sa[i] = i;
    r[i] = i < n ? s[i] : -1;
  }
  for (k = 1; k <= n; k *= 2) {
    sort(sa, sa + n + 1, comp);
    tmp[sa[0]] = 0;
    for (int i = 1; i <= n; i++) {
      tmp[sa[i]] = tmp[sa[i - 1]] + comp(sa[i - 1], sa[i]);
    }
    for (int i = 0; i <= n; i++) r[i] = tmp[i];
  }
}
char t[1010];
int T;
int c(int i) {
  int j = 0;
  for (; j < T && s[i + j] == t[j]; j++)
    ;
  return j < T ? t[j] - s[i + j] : 0;
}
bool func() {
  int f = 0, l = n + 1;
  while (l - f > 1) {
    int m = (f + l) / 2;
    if (c(sa[m]) < 0)
      l = m;
    else
      f = m;
  }
  return c(sa[f]) == 0;
}
int main() {
  gets(s);
  int p;
  scanf("%d\n", &p);
  construct();
  for (; gets(t);) {
    T = strlen(t);
    puts(func() ? "1" : "0");
  }
}
