#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void priv(vector<T> a) {
  for (int i = 0; i < a.size(); i++) {
    cerr << a[i] << ((i == a.size() - 1) ? "\n" : " ");
  }
}
long long gcd(long long a, long long b) {
  int c = max(a, b);
  int d = min(a, b);
  return c == 0 || d == 0 ? c : gcd(c % d, d);
}
long long lcm(long long a, long long b) {
  return a == 0 || b == 0 ? 0 : a * b / gcd(a, b);
}
long long fact(long long a) {
  long long b = 1;
  for (int i = 1; i <= a; i++) b *= i;
  return b;
}
int n;
string s;
bool solve(string t) {
  int m = t.size();
  map<char, int> f;
  for (int i = 0; i < m; i++) f[t[i]] = m - 1 - i;
  int p = m - 1;
  while (p < n) {
    int k = m - 1;
    while (k >= 0 && t[k] == s[p]) {
      k--;
      p--;
    }
    if (k == -1)
      return true;
    else {
      if (f.find(s[p]) == f.end())
        p += m;
      else
        p += max(f[s[p]], m - k);
    }
  }
  return false;
}
int main() {
  cin >> s;
  n = s.size();
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string t;
    cin >> t;
    cout << solve(t) << endl;
  }
  return 0;
}
