#include <bits/stdc++.h>
using namespace std;
vector<string> sa;
string P;
int Plen;
void qmultisort(vector<string> &src, int size, int suffix) {
  if (size <= 1) {
    return;
  }
  vector<string> lower, middle, larger;
  char pivot = src[size / 2][suffix];
  for (int i = 0; i < size; i++) {
    if (src[i][suffix] == pivot) {
      middle.push_back(src[i]);
    } else if (src[i][suffix] < pivot) {
      lower.push_back(src[i]);
    } else {
      larger.push_back(src[i]);
    }
  }
  int lowsize = lower.size(), midsize = middle.size(), larsize = larger.size(),
      now = 0;
  qmultisort(lower, lowsize, suffix);
  qmultisort(middle, midsize, suffix + 1);
  qmultisort(larger, larsize, suffix);
  for (int i = 0; i < lowsize; i++) {
    src[now++] = lower[i];
  }
  for (int i = 0; i < midsize; i++) {
    src[now++] = middle[i];
  }
  for (int i = 0; i < larsize; i++) {
    src[now++] = larger[i];
  }
}
bool binary_search(int left, int right) {
  if (left == right) {
    if (P == sa[left].substr(0, Plen)) {
      return true;
    } else {
      return false;
    }
  }
  int pivot = (left + right) / 2;
  if (P < sa[pivot]) {
    return binary_search(0, pivot - 1);
  } else {
    return binary_search(pivot + 1, right);
  }
}
int main() {
  string T;
  int Tlen, n;
  cin >> T;
  Tlen = T.size();
  sa.resize(Tlen);
  for (int i = 0; i < Tlen; i++) {
    sa[i] = T.substr(i);
  }
  qmultisort(sa, Tlen, 0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> P;
    Plen = P.size();
    cout << binary_search(0, Tlen - 1) << endl;
  }
  return 0;
}
