#include <bits/stdc++.h>
using namespace std;
const long long int E = 1e18 + 7;
const long long int MOD = 1000000007;
class suffix_array {
 private:
  struct node {
    long long int begin;
    long long int Rank;
    node *next;
    bool operator<(const node &N) const {
      if (Rank == N.Rank) {
        return (next == NULL ? -1 : next->Rank) <
               (N.next == NULL ? -1 : N.next->Rank);
      }
      return Rank < N.Rank;
    }
    node(long long int begin = 0, long long int Rank = 0, node *next = NULL)
        : begin(begin), Rank(Rank), next(next) {}
  };
  static bool pointer_cmp(node *&a, node *&b) { return (*a) < (*b); }
  vector<node *> sa;
  vector<long long int> Rank;
  const string s;
  void build() {
    for (int i = 0; i < s.size(); i++) {
      *sa[i] = {i, s[i], sa[i + 1]};
    }
    sa[s.size()]->begin = s.size();
    sa[s.size()]->Rank = -1;
    sa[s.size()]->next = NULL;
    vector<node *> Next(s.size() + 1);
    for (long long int k = 1; k <= s.size(); k <<= 1) {
      sort(sa.begin(), sa.end(), pointer_cmp);
      Rank[sa[0]->begin] = 0;
      Next[0] = (sa[0]->next == NULL ? NULL : sa[0]->next->next);
      for (int i = 1; i <= s.size(); i++) {
        Rank[sa[i]->begin] =
            Rank[sa[i - 1]->begin] + (*sa[i - 1] < *sa[i] ? 1 : 0);
        Next[i] = (sa[i]->next == NULL ? NULL : sa[i]->next->next);
      }
      for (int i = 0; i <= s.size(); i++) {
        sa[i]->Rank = Rank[sa[i]->begin];
        sa[i]->next = Next[i];
      }
    }
    for (int i = 0; i <= s.size(); i++) {
      Next[sa[i]->begin] = sa[i];
    }
    for (int i = 0; i <= s.size(); i++) {
      sa[i]->next = sa[i]->begin == s.size() ? NULL : Next[sa[i]->begin + 1];
    }
  }
  int compare(const unsigned long &saf, const string &str) {
    for (int i = 0; i < str.size(); i++) {
      if (sa[saf]->begin + i >= s.size()) {
        return -1;
      }
      if (s[sa[saf]->begin + i] != str[i]) {
        return s[sa[saf]->begin + i] < str[i] ? -1 : 1;
      }
    }
    return 0;
  }

 public:
  suffix_array(const string &str)
      : s(str), Rank(str.size() + 1), sa(str.size() + 1) {
    for (int i = 0; i <= str.size(); i++) {
    }
    build();
  }
  long long int rank(const unsigned long &where) const { return Rank[where]; }
  unsigned long size() const { return sa.size(); }
  const node &operator[](const unsigned long &where) const {
    return *sa[where];
  }
  unsigned long lower_bound(const string &sub) {
    long long int l = 0;
    long long int r = s.size();
    while (r - l > 4) {
      long long int m = l + (r - l) / 2;
      if (compare(m, sub) == -1) {
        l = m + 1;
      } else {
        r = m;
      }
    }
    for (long long int i = l; i <= r; i++) {
      if (compare(i, sub) >= 0) {
        return i;
      }
    }
    return r + 1;
  }
  unsigned long upper_bound(const string &sub) {
    long long int l = 0;
    long long int r = s.size();
    while (r - l > 4) {
      long long int m = l + (r - l) / 2;
      if (compare(m, sub) <= 0) {
        l = m + 1;
      } else {
        r = m;
      }
    }
    for (long long int i = l; i <= r; i++) {
      if (compare(i, sub) > 0) {
        return i;
      }
    }
    return r + 1;
  }
  bool match(const string &sub) {
    long long int l = 0;
    long long int r = s.size();
    while (r - l > 4) {
      long long int m = l + (r - l) / 2;
      int st = compare(m, sub);
      if (st == 0) {
        return true;
      } else if (st == -1) {
        l = m + 1;
      } else {
        r = m - 1;
      }
    }
    for (long long int i = l; i <= r; i++) {
      if (compare(i, sub) == 0) {
        return true;
      }
    }
    return false;
  }
};
int main() {
  string t;
  cin >> t;
  suffix_array second(t);
  long long int q;
  cin >> q;
  while (q--) {
    string p;
    cin >> p;
    cout << second.match(p) << endl;
  }
  return 0;
}
