#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  s += '$';
  int n = s.size();
  vector<int> suff(n);
  iota(suff.begin(), suff.end(), 0);
  {
    const char *str = s.c_str();
    sort(suff.begin(), suff.end(),
         [&](int a, int b) { return str[a] < str[b]; });
  }
  vector<pair<char, int>> sorted(n);
  for (int i = 0; i < n; i++) sorted[i] = {s[(suff[i] - 1 + n) % n], i};
  sort(sorted.begin(), sorted.end());
  int T;
  for (cin >> T; T--;) {
    string q;
    cin >> q;
    int start = 0, stop = n, idx = q.size() - 1;
    for (; idx >= 0; idx--) {
      pair<char, int> ql = {q[idx], start}, qr = {q[idx], stop};
      start = lower_bound(sorted.begin(), sorted.end(), ql) - sorted.begin();
      stop = lower_bound(sorted.begin(), sorted.end(), qr) - sorted.begin();
      if (start == stop) break;
    }
    if (idx < 0) {
      puts("1");
    } else {
      puts("0");
    }
  }
}
