#include <bits/stdc++.h>
using namespace std;
int kmp(string t, string p) {
  int i, j;
  int n = t.size();
  int m = p.size();
  vector<int> nx(m + 1, 0);
  nx[0] = -1;
  for (i = 0, j = -1; i < m; i++, j++, nx[i] = j) {
    while ((j >= 0) && (p[i] != p[j])) j = nx[j];
  }
  for (i = 0, j = 0; j < m && i < n; i++, j++) {
    while ((j >= 0) && (t[i] != p[j])) j = nx[j];
  }
  if (j == m)
    return i - m;
  else
    return -1;
}
int main() {
  string t;
  cin >> t;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string p;
    cin >> p;
    int ans = kmp(t, p);
    if (ans != -1)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
