#include <bits/stdc++.h>
using namespace std;
inline void output() { cerr << endl; }
template <typename First, typename... Rest>
inline void output(const First &first, const Rest &...rest) {
  cerr << first << " ";
  output(rest...);
}
static const int NUM_CHILDREN = 26;
static const char MIN_CHAR = 'a';
struct Trie {
  int num;
  Trie *next[NUM_CHILDREN];
  Trie() : num(-1) { fill(next, next + NUM_CHILDREN, (Trie *)0); }
};
void construct(Trie *trie, const vector<string> &strings) {
  for (int i = 0; i < (strings.size()); i++) {
    Trie *p = trie;
    for (auto c : strings[i]) {
      int idx = c - MIN_CHAR;
      if (!p->next[idx]) p->next[idx] = new Trie;
      p = p->next[idx];
    }
    p->num = i;
  }
}
void dump(Trie *p, string s) {
  if (p->num != -1) cerr << s << endl;
  for (int i = 0; i < NUM_CHILDREN; ++i) {
    if (p->next[i]) {
      dump(p->next[i], s + char(i + MIN_CHAR));
    }
  }
}
void search(Trie *trie, const string &s, vector<bool> &exist) {
  Trie *p = trie;
  for (auto c : s) {
    if (p->num != -1) exist[p->num] = true;
    int idx = c - MIN_CHAR;
    if (!p->next[idx]) return;
    p = p->next[idx];
  }
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<string> strings(q);
  for (int i = 0; i < (q); i++) cin >> strings[i];
  Trie *trie = new Trie;
  construct(trie, strings);
  vector<bool> exist(q);
  for (int i = 0; i < (s.size()); i++) {
    search(trie, s.substr(i), exist);
  }
  for (int i = 0; i < (q); i++) {
    cout << exist[i] << endl;
  }
}
