#include <bits/stdc++.h>
using namespace std;
struct P {
  static vector<P*> data;
  map<char, P*> next;
  P() {}
  void initialize(char* str) {
    P* tar = this;
    while (*str) {
      P** lpnx;
      if (tar != this && *(lpnx = &(this->next[*str])) == NULL) *lpnx = new P();
      data.push_back(tar = tar->next[*str] = new P());
      ++str;
    }
  }
  void add(char* str, int index) {
    P** lpnx;
    str += index;
    P* tar = this->next[*str];
    ++str;
    ++index;
    if (*(lpnx = &(tar->next[*str])) == NULL) *lpnx = data[index];
  }
  int find(char* str) {
    P* tar = this;
    while (*str) {
      P** lpnx;
      if (*(lpnx = &(tar->next[*str])) == NULL) return 0;
      tar = *lpnx;
      ++str;
    }
    return 1;
  }
};
vector<P*> P::data;
int main() {
  string s;
  int q;
  cin >> s >> q;
  P* root = new P();
  char* str = (char*)s.c_str();
  root->initialize(str);
  int len = s.size() - 1;
  for (int i = 1; i < len; ++i) root->add(str, i);
  for (int i = 0; i < q; ++i) {
    string t;
    cin >> t;
    cout << root->find((char*)t.c_str()) << endl;
  }
}
