#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long int linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
typedef struct SAManberMyers_ {
  string s;
  vector<int> rank;
  vector<int> tmp;
  vector<int> sa;
  int n, k;
  SAManberMyers_(string ss) {
    s = ss;
    n = s.size();
    rank.resize(n + 1);
    tmp.resize(n + 1);
    sa.resize(n + 1);
    k = 0;
    construct();
  }
  bool comp(const int &a, const int &b) {
    if (rank[a] != rank[b]) return rank[a] < rank[b];
    int ra = a + k <= n ? rank[a + k] : -1;
    int rb = b + k <= n ? rank[b + k] : -1;
    return ra < rb;
  }
  void construct() {
    for (int i = 0; i <= n; i++) {
      sa[i] = i;
      rank[i] = i < n ? s[i] : -1;
    }
    for (k = 1; k <= n; k *= 2) {
      sort(sa.begin(), sa.end(),
           [this](const int &a, const int &b) { return comp(a, b); });
      tmp[sa[0]] = 0;
      for (int i = 1; i <= n; i++) {
        tmp[sa[i]] = tmp[sa[i - 1]] + (comp(sa[i - 1], sa[i]) ? 1 : 0);
      }
      for (int i = 0; i <= n; i++) {
        rank[i] = tmp[i];
      }
    }
  }
} SAManberMyers;
vector<int> sa_search_(SAManberMyers &sa, string &s, string &t) {
  vector<int> res;
  t += "$";
  s += "$";
  int ld = -1;
  int rd = sa.sa.size() - 1;
  while (rd - ld > 1) {
    int md = (rd + ld) / 2;
    if (s.substr(sa.sa[md]) < t)
      ld = md;
    else
      rd = md;
  }
  t = t.substr(0, t.size() - 1);
  while (rd < sa.sa.size()) {
    if (s.substr(sa.sa[rd], t.size()) != t) break;
    res.push_back(sa.sa[rd]);
    rd++;
  }
  sort(res.begin(), res.end());
  return res;
}
vector<int> sa_search(string s, string t) {
  SAManberMyers sa(s);
  vector<int> res = sa_search_(sa, s, t);
  return res;
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  SAManberMyers sa(s);
  int q;
  cin >> q;
  for (int i = (0); i < (q); ++i) {
    string p;
    cin >> p;
    auto res = sa_search_(sa, s, p);
    if (((int)(res).size()) >= 1)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
