#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void chmin(T &t, U f) {
  if (t > f) t = f;
}
template <class T, class U>
void chmax(T &t, U f) {
  if (t < f) t = f;
}
namespace SA {
const int MAX = 1000000;
int N, K;
int tmp[MAX + 1], rank[MAX + 1];
bool compare_sa(int i, int j) {
  if (rank[i] != rank[j])
    return rank[i] < rank[j];
  else {
    int ri = (i + K <= N) ? rank[i + K] : -1;
    int rj = (j + K <= N) ? rank[j + K] : -1;
    return ri < rj;
  }
}
vector<int> construct_sa(string S) {
  N = S.size();
  vector<int> sa(N + 1);
  for (int i = 0; i <= N; i++) sa[i] = i;
  for (int i = 0; i <= N; i++) {
    rank[i] = i == N ? -1 : S[i];
  }
  for (K = 1; K <= N; K *= 2) {
    sort(sa.begin(), sa.end(), compare_sa);
    tmp[sa[0]] = 0;
    for (int i = 1; i <= N; i++) {
      tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
    }
    for (int i = 0; i <= N; i++) rank[i] = tmp[i];
  }
  return sa;
}
}  // namespace SA
string S;
vector<int> sa;
int Q;
bool exist(string T) {}
bool contain(string &S, vector<int> &sa, string &T) {
  int a = 0, b = S.size();
  while (b - a > 1) {
    int c = (a + b) / 2;
    if (S.compare(sa[c], T.size(), T) < 0)
      a = c;
    else
      b = c;
  }
  return S.compare(sa[b], T.size(), T) == 0;
}
signed main() {
  cin >> S;
  sa = SA::construct_sa(S);
  cin >> Q;
  for (int i = 0; i < (sa.size()); i++)
    cout << S.substr(sa[i], S.size() - sa[i]) << endl;
  while (Q--) {
    string T;
    cin >> T;
    if (contain(S, sa, T))
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
