#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int a[1000000];
int b[1000000];
int main() {
  cin >> s;
  n = s.size();
  vector<pair<int, int> > v;
  for (int i = 0; i < (n); ++i) {
    v.push_back(pair<int, int>(s[i], i));
  }
  sort(v.begin(), v.end());
  a[v[0].second] = 0;
  for (int i = 0; i < (n - 1); ++i) {
    a[v[i + 1].second] = a[v[i].second] + (v[i].first != v[i + 1].first);
  }
  for (int i = 0; i < (20); ++i) {
    vector<pair<pair<int, int>, int> > v;
    for (int j = 0; j < (n); ++j) {
      if (j + (1 << i) < n) {
        v.push_back(pair<pair<int, int>, int>(
            pair<int, int>(a[j], a[j + (1 << i)]), j));
      } else {
        v.push_back(pair<pair<int, int>, int>(pair<int, int>(a[j], -1), j));
      }
    }
    sort(v.begin(), v.end());
    a[v[0].second] = 0;
    for (int j = 0; j < (n - 1); ++j) {
      a[v[j + 1].second] = a[v[j].second] + (v[j].first != v[j + 1].first);
    }
  }
  for (int i = 0; i < (n); ++i) {
    b[a[i]] = i;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    string t;
    cin >> t;
    int l = 0, r = n;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (string(s, b[m], min((int)t.size(), n - b[m])) <= t) {
        l = m;
      } else {
        r = m;
      }
    }
    cout << int(string(s, b[l], min((int)t.size(), n - b[l])) == t) << endl;
  }
}
