#include <bits/stdc++.h>
using namespace std;
struct P {
  int a, b, idx;
  P() { a = b = idx = 0; }
  P(int a, int b, int idx) : a(a), b(b), idx(idx){};
  bool operator<(const P &A) const {
    if (a != A.a) return a > A.a;
    return b > A.b;
  }
};
char ch[1 << 20];
P r[1 << 20];
vector<int> Sort() {
  int n = strlen(ch);
  vector<int> R(n + 1), res(n + 1);
  for (int i = 0; i <= n; i++) R[i] = ch[i];
  for (int i = 1; i <= n; i *= 2) {
    for (int j = 0; j <= n; j++) r[j] = P(R[j], (j + i <= n) ? R[j + i] : 0, j);
    sort(r, r + n + 1);
    R[r[0].idx] = 0;
    for (int j = 1, C = 0; j <= n; j++) {
      if (r[j - 1] < r[j]) C++;
      R[r[j].idx] = C;
    }
  }
  for (int i = 0; i <= n; i++) res[R[i]] = i;
  return res;
}
int check(vector<int> &a, char *x) {
  int L = 0, M, R = strlen(ch) + 1;
  int m = strlen(x);
  while (L < R) {
    M = (L + R) / 2;
    if (strncmp(ch + a[M], x, m) <= 0)
      R = M;
    else
      L = M + 1;
  }
  return strncmp(ch + a[L], x, m) == 0;
}
int main() {
  scanf("%s", ch);
  int q;
  cin >> q;
  vector<int> Rank = Sort();
  char a[1001];
  while (q--) {
    scanf("%s", a);
    printf("%d\n", check(Rank, a));
  }
  return 0;
}
