#include <bits/stdc++.h>
using namespace std;
struct RollingHash {
  static const unsigned long long p = 100000007;
  string s;
  int n;
  vector<unsigned long long> pow, phash;
  RollingHash(const string& s)
      : s(s), n(int(s.size())), pow(n + 1), phash(n + 1) {
    pow[0] = 1, phash[0] = 0;
    for (int i = 0; i < int(n); ++i) {
      phash[i + 1] = s[i] + phash[i] * p;
      pow[i + 1] = pow[i] * p;
    }
  }
  inline bool operator()(const int& i, const int& j) {
    const int k = lcp2(i, j, 0, max(n - i, n - j) + 1);
    if (i + k >= n) return 1;
    if (j + k >= n) return 0;
    return s[i + k] <= s[j + k];
  }
  inline unsigned long long hash(const int& b, const int& e) {
    return phash[e] - phash[b] * pow[e - b];
  }
  inline int lcp2(const int& i, const int& j, const int& l, const int& r) {
    if (r - l <= 1) return l;
    int m = (l + r) / 2;
    if (hash(i, i + m) == hash(j, j + m)) return lcp2(i, j, m, r);
    return lcp2(i, j, l, m);
  }
};
vector<int> suffixArray(const RollingHash& rh) {
  vector<int> sa(rh.n + 1);
  for (int i = 0; i < int(rh.n + 1); ++i) sa[i] = i;
  sort((sa).begin(), (sa).end(), rh);
  if (10000 < rh.s.size()) assert(false);
  return sa;
}
bool contain(const string& S, const vector<int>& sa, const string& T) {
  int a = 0, b = S.length();
  while (b - a > 1) {
    int c = (a + b) / 2;
    if (S.compare(sa[c], T.length(), T) < 0)
      a = c;
    else
      b = c;
  }
  return S.compare(sa[b], T.length(), T) == 0;
}
int main(void) {
  int n;
  string s, t;
  cin >> s;
  RollingHash rh = RollingHash(s);
  vector<int> sa = suffixArray(rh);
  cin >> n;
  cin.ignore();
  while (n--) {
    cin >> t;
    printf("%d\n", contain(s, sa, t));
  }
  return 0;
}
