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