#include <bits/stdc++.h>
using namespace std;
class RollingHash {
 public:
  RollingHash(std::string _s) : s(_s){};
  std::vector<int> search(std::string p);

 private:
  unsigned long long int PatternHash(std::string s);
  void Hashing(int m);
  std::string s;
  std::vector<unsigned long long int> rh;
  int length = 0;
};
std::vector<int> RollingHash::search(std::string p) {
  if (p.length() != length) {
    Hashing(p.length());
    length = p.length();
  }
  unsigned long long int pHash = PatternHash(p);
  std::vector<int> res;
  for (int i = 0; i < s.length() - length + 1; i++) {
    if (pHash == rh[i]) {
      res.push_back(i);
    }
  }
  return res;
}
unsigned long long int RollingHash::PatternHash(std::string s) {
  unsigned long long int base = 1e9 + 7, res = 0;
  for (int i = 0; i < s.length(); i++) {
    res *= base;
    res += s[i];
  }
  return res;
}
void RollingHash::Hashing(int m) {
  rh.clear();
  int n = s.length();
  if (n < m) return;
  rh.resize(n - m + 1, 0);
  unsigned long long int base = 1e9 + 7, t = 1;
  for (int i = m - 1; i >= 0; i--) {
    rh[0] += t * s[i];
    t *= base;
  }
  for (int i = 1; i <= n - m; i++) {
    rh[i] = rh[i - 1] * base + s[i + m - 1] - s[i - 1] * t;
  }
}
int main() {
  string s, t;
  int q;
  std::cin >> s >> q;
  RollingHash rh(s);
  for (int i = 0; i < q; i++) {
    std::cin >> t;
    vector<int> ans = rh.search(t);
    if (ans.size() == 0) {
      std::cout << 0 << std::endl;
    } else {
      std::cout << 1 << std::endl;
    }
  }
  return 0;
}
