#include <bits/stdc++.h>
using namespace std;
int N, Q, sa[1000009];
string s;
unsigned long long p[1000009], h[1000009];
int lcp(int x, int y) {
  int l = 0, r = min(N - x, N - y) + 1;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (h[x + m] - x[h] * p[m] == h[y + m] - h[y] * p[m])
      l = m;
    else
      r = m;
  }
  return l;
}
bool compare_sa(int i, int j) {
  int k = lcp(i, j);
  if (i + k >= N) return true;
  if (j + k >= N) return false;
  return s[i + k] <= s[j + k];
}
bool contain(string &t) {
  int a = 0, b = N;
  while (b - a > 1) {
    int c = (a + b) >> 1;
    if (s.compare(sa[c], t.size(), t) < 0)
      a = c;
    else
      b = c;
  }
  return s.compare(sa[b], t.size(), t) == 0;
}
int main() {
  cin >> s >> Q;
  N = s.size();
  p[0] = 1;
  for (int i = 0; i < s.size(); i++) {
    p[i + 1] = p[i] * 257;
    h[i + 1] = h[i] * 257 + s[i];
  }
  iota(sa, sa + N + 1, 0);
  sort(sa, sa + N + 1, compare_sa);
  for (int i = 0; i < Q; i++) {
    string t;
    cin >> t;
    cout << contain(t) << endl;
  }
  return 0;
}
