#include <bits/stdc++.h>
using namespace std;
struct d {
  int a, b, c;
  d() {}
  d(int A, int B, int C) { a = A, b = B, c = C; };
  bool operator<(const d& r) const {
    if (a != r.a) return a < r.a;
    return b < r.b;
  }
};
int n, slen, tlen, r[2100005];
char s[2100005], t[1005];
d ran[2100005];
pair<int, int> a[2100005];
void init() {
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < slen; j++)
      if ('a' + i == s[j]) r[j] = i + 1;
  int x = 1;
  while (x < slen) {
    for (int i = 0; i < slen; i++) {
      int a = i + x;
      if (a > slen) a = slen;
      ran[i] = d(r[i], r[a], i);
    }
    sort(ran, ran + slen);
    int cnt = 1;
    for (int i = 0; i < slen; i++) {
      r[ran[i].c] = cnt;
      if (ran[i].a == ran[i + 1].a && ran[i].b == ran[i + 1].b) continue;
      cnt++;
    }
    x *= 2;
  }
  for (int i = 0; i < slen; i++) a[i] = pair<int, int>(r[i], i);
  sort(a, a + slen);
}
bool bynary_search() {
  int L = 0, R = slen;
  while (L < R) {
    int M = (L + R) / 2;
    if (strncmp(s + a[M].second, t, tlen) < 0)
      L = M + 1;
    else
      R = M;
  }
  if (!strncmp(s + a[L].second, t, tlen)) return true;
  return false;
}
int main() {
  scanf("%s%d", s, &n);
  slen = strlen(s);
  init();
  while (n--) {
    scanf("%s", t);
    tlen = strlen(t);
    if (bynary_search())
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}
