#include <bits/stdc++.h>
using namespace std;
int main() {
  string T, P;
  long Q;
  cin >> T >> Q;
  for (long i = 0; i < Q; i++) {
    cin >> P;
    if (T.find(P, 0) != -1)
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}
