#include <bits/stdc++.h>
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const long long infll = (long long)1e+18 + 10;
class RollingHash {
 private:
  static const unsigned long long B = (unsigned long long)1e+8 + 7;
  std::string text;
  int texSize;
  std::vector<unsigned long long> pow, phash;
  inline unsigned long long TextHash(int s, int e) {
    return phash[e] - phash[s] * pow[e - s];
  }

 public:
  RollingHash(std::string tex)
      : text(tex), texSize(text.size()), pow(texSize + 1), phash(texSize + 1) {
    pow[0] = 1;
    phash[0] = 0;
    for (int i = 0; i < texSize; ++i) {
      phash[i + 1] = phash[i] * B + text[i];
      pow[i + 1] = pow[i] * B;
    }
  }
  bool find(std::string pat) {
    int patSize = pat.size();
    if (patSize > texSize) return false;
    unsigned long long patHash = 0;
    for (int i = 0; i < patSize; ++i) patHash = patHash * B + pat[i];
    for (int i = 0; i < texSize - patSize + 1; ++i) {
      if (TextHash(i, i + patSize) == patHash) {
        return true;
      }
    }
    return false;
  }
};
int n;
int main() {
  std::string a;
  std::cin >> a >> n;
  RollingHash rh(a);
  for (int i = 0; i < n; ++i) {
    std::string b;
    std::cin >> b;
    std::cout << (rh.find(b) ? 1 : 0) << std::endl;
    ;
  }
  return 0;
}
