#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';
  TrieNode *adj[36];
  TrieNode(int depth, TrieNode *parent) : depth(depth), parent(parent) {
    TrieNode();
  }
  TrieNode() { fill_n(adj, 36, nullptr); }
  TrieNode *GetNeighbor(char c) { return adj[getidx(c)]; }
  static int getidx(char c) { return isalpha(c) ? (c - 'a') : (26 + c - '0'); }
};
using np = TrieNode *;
void BuildTrie(np cur, string &s, int i) {
  for (int j = 0; j < s.size(); ++j) {
    np neighborptr = cur->GetNeighbor(s[j]);
    if (!neighborptr) {
      cur->adj[TrieNode::getidx(s[j])] = new TrieNode(cur->depth + 1, cur);
    }
    cur = cur->GetNeighbor(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->GetNeighbor(cur->last))
        sufcur = sufcur->suf;
      if (np neighbor = sufcur->GetNeighbor(cur->last)) {
        cur->suf = neighbor;
      } else {
        cur->suf = root;
      }
    }
    np outcur = cur->suf;
    while (outcur && !outcur->is_word) outcur = outcur->suf;
    cur->out = outcur;
    for (int i = 0; i < 36; ++i)
      if (cur->adj[i]) to_visit.push(cur->adj[i]);
  }
}
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->GetNeighbor(c)) cur = cur->suf;
    if (np out = cur->GetNeighbor(c)) cur = out;
    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;
}
