#include <bits/stdc++.h>
using namespace std;
struct TrieNode {
  int is_word = 0, depth = 0;
  vector<int> word_indices;
  TrieNode *suf = nullptr, *out = nullptr, *parent = nullptr;
  char last = '\0';
  map<char, TrieNode *> adj;
  TrieNode(int depth, TrieNode *parent) : depth(depth), parent(parent) {}
  TrieNode() = default;
};
using np = TrieNode *;
void BuildTrie(np cur, string &s, int i) {
  for (int j = 0; j < s.size(); ++j) {
    if (!(cur->adj.count(s[j]))) {
      cur->adj[s[j]] = new TrieNode(cur->depth + 1, cur);
    }
    cur = cur->adj[s[j]];
    cur->last = s[j];
  }
  cur->is_word = 1;
  cur->word_indices.push_back(i);
}
void AddEdges(np root) {
  queue<np> to_visit;
  to_visit.push(root);
  while (!to_visit.empty()) {
    np cur = to_visit.front();
    to_visit.pop();
    if (cur->depth == 1) {
      cur->suf = root;
    } else if (cur->depth > 1) {
      np sufcur = cur->parent->suf;
      while (sufcur != root && !sufcur->adj.count(cur->last))
        sufcur = sufcur->suf;
      if (sufcur->adj.count(cur->last)) {
        cur->suf = sufcur->adj[cur->last];
      } else {
        cur->suf = root;
      }
    }
    np outcur = cur->suf;
    while (outcur && !outcur->is_word) outcur = outcur->suf;
    cur->out = outcur;
    for (auto &kv : cur->adj) to_visit.push(kv.second);
  }
}
int main() {
  string T;
  cin >> T;
  int q;
  cin >> q;
  np root = new TrieNode;
  string p;
  for (int i = 0; cin >> p; ++i) BuildTrie(root, p, i);
  AddEdges(root);
  np cur = root;
  unordered_set<int> matched;
  for (char c : T) {
    while (cur != root && !cur->adj.count(c)) {
      cur = cur->suf;
    }
    if (cur->adj.count(c)) cur = cur->adj[c];
    if (cur->is_word)
      matched.insert(cur->word_indices.begin(), cur->word_indices.end());
    np outcur = cur->out;
    while (outcur) {
      matched.insert(outcur->word_indices.begin(), outcur->word_indices.end());
      outcur = outcur->out;
    }
  }
  for (int i = 0; i < q; ++i) cout << matched.count(i) << endl;
}
