#include <bits/stdc++.h>
using namespace std;
vector<int> suffixArray(char* s) {
  int len = strlen(s);
  vector<int> res(len + 1);
  vector<pair<pair<int, int>, int> > tmp(len + 1);
  for (int i = 0; i <= len; i++) res[i] = s[i];
  for (int k = 1; k <= len; k *= 2) {
    for (int i = 0; i <= len; i++) {
      tmp[i].first.first = res[i];
      tmp[i].first.second = (i + k <= len ? res[i + k] : 0);
      tmp[i].second = i;
    }
    sort(tmp.begin(), tmp.end());
    int C = 0;
    for (int i = 0; i <= len; i++) {
      int id = tmp[i].second;
      if (i && (tmp[i - 1].first < tmp[i].first)) C++;
      res[id] = C;
    }
  }
  vector<int> res2(len + 1);
  for (int i = 0; i <= len; i++) res2[res[i]] = i;
  return res2;
}
char s[1000005];
char t[1000005];
int main() {
  scanf("%s", s);
  vector<int> ans = suffixArray(s);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%s", t);
    int len = strlen(t);
    int l = 0, r = ans.size(), m;
    while (r - l > 1) {
      m = (l + r) / 2;
      if (strncmp(s + ans[m], t, len) <= 0)
        l = m;
      else
        r = m;
    }
    if (strncmp(s + ans[l], t, len) == 0)
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}
