#include <bits/stdc++.h>
using namespace std;
const unsigned long long B = 10007;
void RollingHash(string T, string P) {
  int S = 0;
  int t = T.size();
  int p = P.size();
  unsigned long long x = 1;
  for (int i = 0; i < p; i++) x *= B;
  unsigned long long th = 0, ph = 0;
  for (int i = 0; i < p; i++) th = th * B + T[i];
  for (int i = 0; i < p; i++) ph = ph * B + P[i];
  for (int i = 0; i + p <= t; i++) {
    if (th == ph) {
      printf("1\n");
      return;
    }
    if (i + p < t) th = th * B + T[i + p] - T[i] * x;
  }
  printf("0\n");
}
int main() {
  string T;
  cin >> T;
  int Q;
  cin >> Q;
  vector<string> P(Q);
  for (int i = 0; i < Q; i++) {
    cin >> P[i];
    RollingHash(T, P[i]);
  }
  return 0;
}
