#include <bits/stdc++.h>
using namespace std;
bool solve(string T, string P, int len_T, int len_P) {
  int k = 0;
  int x, y;
  if (len_T < len_P) return false;
  while (k <= len_T - len_P) {
    for (x = len_P - 1; x >= 0; x--) {
      if (P[x] != T[k + x]) break;
    }
    if (x < 0) return true;
    for (y = x; y >= 0; y--) {
      if (P[y] == T[k + x]) break;
    }
    k += x - y;
  };
  return false;
}
int main() {
  string T, P;
  int q;
  cin >> T >> q;
  int n = T.size();
  int m;
  while (q) {
    cin >> P;
    m = P.size();
    cout << solve(T, P, n, m) << endl;
    q--;
  };
  return 0;
}
