#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int, int>;
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9 + 7;
void cioacc() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
vector<string> make_suffix_array(const string &s) {
  vector<string> res;
  for (ll i = (0); i < ((ll)s.size() + 1); i++) {
    string tmp(s.begin() + i, s.end());
    res.push_back(tmp);
  }
  sort((res).begin(), (res).end());
  return res;
}
int main() {
  string t;
  int n;
  cin >> t >> n;
  auto suf = make_suffix_array(t);
  for (ll i = (0); i < (n); i++) {
    string q;
    cin >> q;
    size_t sz = q.size();
    auto itr = lower_bound((suf).begin(), (suf).end(), q);
    bool flag = false;
    do {
      if (itr == suf.end()) break;
      string cut(itr->begin(), (itr->begin()) + min(sz, itr->size()));
      if (cut == q) {
        cout << 1 << endl;
        flag = true;
        break;
      } else if (cut > q) {
        break;
      }
      ++itr;
    } while (true);
    if (!flag) cout << 0 << endl;
  }
}
