#include <bits/stdc++.h>
using namespace std;
bool has(map<char, int> m, char c) {
  if (m.find(c) == m.end())
    return false;
  else
    return true;
}
int bm(string t, string p) {
  int i, j;
  int n = t.size();
  int m = p.size();
  map<char, int> skip;
  for (int k = 0; k < m; k++) {
    skip[p[k]] = m - k - 1;
  }
  for (i = m - 1, j = m - 1; j > 0; i--, j--) {
    while (t[i] != p[j]) {
      int x = (has(skip, t[i])) ? skip[t[i]] : m;
      i += ((m - j > x) ? m - j : x);
      if (i >= n) return -1;
      j = m - 1;
    }
  }
  return i;
}
int main() {
  string t;
  cin >> t;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string p;
    cin >> p;
    int ans = bm(t, p);
    if (ans != -1)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
