#include <bits/stdc++.h>
using namespace std;
struct RollingHash {
  static const unsigned long long p = 100000007;
  string s;
  int n;
  unsigned long long *pow, *phash;
  RollingHash(const string &s) : s(s), n(int(s.size())) {
    pow = new unsigned long long[n + 1];
    phash = new unsigned long long[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;
    }
  }
  ~RollingHash() { free(pow), free(phash); }
  inline bool operator()(const int &i, const int &j) const {
    const int k = lcp(i, j);
    return i + k >= n ? true : j + k >= n ? false : s[i + k] <= s[j + k];
  }
  inline unsigned long long hash(const int &b, const int &e) const {
    return phash[e] - phash[b] * pow[e - b];
  }
  inline int lcp(const int &i, const int &j) const {
    int l = 0, r = n - max(i, j) + 1;
    while (r - l > 1) {
      const int m = (l + r) / 2;
      (hash(i, i + m) == hash(j, j + m) ? l : r) = m;
    }
    return l;
  }
};
int L[1000000], R[1000000];
inline void merge(int *A, const int left, const int mid, const int right,
                  const RollingHash &rh) {
  int n1 = mid - left, n2 = right - mid;
  for (int i = 0; i < int(n1); ++i) L[i] = A[left + i];
  for (int i = 0; i < int(n2); ++i) R[i] = A[mid + i];
  L[n1] = R[n2] = (1 << 29);
  for (int k = left, i = 0, j = 0; k < right; k++) {
    A[k] = rh(L[i], R[j]) ? L[i++] : R[j++];
  }
}
void mergeSort(int *A, const int left, const int right, const RollingHash &rh) {
  if (left + 1 < right) {
    const int mid = (left + right) / 2;
    mergeSort(A, left, mid, rh);
    mergeSort(A, mid, right, rh);
    merge(A, left, mid, right, rh);
  }
}
vector<int> suffixArray(const RollingHash &rh) {
  int n = rh.n + 1, sa[n];
  for (int i = 0; i < int(n); ++i) sa[i] = i;
  mergeSort(sa, 0, n, rh);
  vector<int> res(n);
  for (int i = 0; i < int(n); ++i) res[i] = sa[i];
  return res;
}
bool contain(const string &S, const vector<int> &sa, const string &T) {
  int a = 0, b = int(S.size());
  while (b - a > 1) {
    const int c = (a + b) / 2;
    (S.compare(sa[c], T.length(), T) < 0 ? a : b) = c;
  }
  return S.compare(sa[b], T.length(), T) == 0;
}
int main(void) {
  char str[1000002];
  string s, t;
  scanf("%s", str);
  s = str;
  RollingHash rh = RollingHash(s);
  vector<int> sa = suffixArray(rh);
  int n;
  cin >> n;
  while (n--) {
    scanf("%s", str);
    t = str;
    printf("%d\n", contain(s, sa, t));
  }
  return 0;
}
