#include <bits/stdc++.h>
bool CheckString(std::string A, std::string B) {
  for (unsigned int i = 0; i < A.size(); ++i) {
    if (A[i] == B[0] && A.substr(i, B.size()) == B) {
      return true;
    }
  }
  return false;
}
int main(void) {
  std::ios_base::sync_with_stdio(false);
  std::string T;
  int Q;
  std::cin >> T >> Q;
  std::vector<std::string> P(Q);
  for (int i = 0; i < Q; ++i) {
    std::cin >> P[i];
  }
  for (int i = 0; i < Q; ++i) {
    std::cout << CheckString(T, P[i]) << std::endl;
  }
  return 0;
}
