#include <bits/stdc++.h>
using namespace std;
const long long int E = 1e18 + 7;
const long long int MOD = 1000000007;
long long int n, k;
vector<long long int> Rank;
vector<long long int> tmp;
vector<long long int> sa;
string str;
bool less_cmp(long long int a, const string &s) {
  for (long long int i = a; i < a + s.size(); i++) {
    if (i >= n) {
      return true;
    }
    if (str[i] != s[i - a]) {
      return str[i] < s[i - a];
    }
  }
  return false;
}
bool equal_cmp(long long int a, const string &s) {
  for (long long int i = 0; i < s.size(); i++) {
    if (i + a >= n) {
      return false;
    }
    if (str[i + a] != s[i]) {
      return false;
    }
  }
  return true;
}
bool cmp(long long int i, long long int j) {
  if (Rank[i] != Rank[j]) {
    return Rank[i] < Rank[j];
  }
  return (i + k <= n ? Rank[i + k] : -1) < (i + j <= n ? Rank[j + k] : -1);
}
void build(const string &s) {
  n = s.size();
  sa.resize(n + 1);
  Rank.resize(n + 1);
  tmp.resize(n + 1);
  for (int i = 0; i <= n; i++) {
    sa[i] = i;
    Rank[i] = i < n ? s[i] : -1;
  }
  for (k = 1; k <= n; k++) {
    sort(sa.begin(), sa.end(), cmp);
    tmp[sa[0]] = 0;
    for (int i = 1; i <= n; i++) {
      tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);
    }
    for (int i = 0; i <= n; i++) {
      Rank[i] = tmp[i];
    }
  }
}
bool search(const string &s) {
  long long int l = 0, r = n;
  while (r - l >= 10) {
    long long int m = l + (r - l) / 2;
    if (less_cmp(sa[m], s)) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  for (long long int i = l; i <= r; i++) {
    if (equal_cmp(sa[i], s)) {
      return true;
    }
  }
  return false;
}
int main() {
  cin >> str;
  build(str);
  long long int q;
  cin >> q;
  while (q--) {
    string p;
    cin >> p;
    cout << search(p) << endl;
  }
  return 0;
}
