#include <bits/stdc++.h>
using namespace std;
string sa[1000000], p;
int plen;
bool binary_search(int left, int right) {
  if (left > right) {
    return false;
  }
  int pivot = (left + right) / 2;
  if (p == sa[pivot].substr(0, plen)) {
    return true;
  } else if (p < sa[pivot]) {
    return binary_search(left, pivot - 1);
  } else {
    return binary_search(pivot + 1, right);
  }
}
int main() {
  int len, n;
  string str;
  cin >> str;
  len = str.size();
  for (int i = 0; i < len; i++) {
    sa[i] = str.substr(i);
  }
  sort(sa, sa + len);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p;
    plen = p.size();
    cout << binary_search(0, len - 1) << endl;
  }
  return 0;
}
