#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string s;
int q;
void read() { cin >> s >> q; }
struct node {
  int link, cnt, len;
  map<int, int> next;
};
const int maxn = 2e6 + 3;
int idx, last;
node sa[maxn * 2];
void init_sa() {
  idx = last = 0;
  sa[0] = {-1, 0, 0, {}};
}
void extend_sa(char ch) {
  int curr = ++idx;
  sa[curr] = {-1, 1, sa[last].len + 1, {}};
  int p = last;
  while (p != -1 && !sa[p].next.count(ch - 'a'))
    sa[p].next[ch - 'a'] = curr, p = sa[p].link;
  if (p == -1)
    sa[curr].link = 0;
  else {
    int q = sa[p].next[ch - 'a'];
    if (sa[q].len == sa[p].len + 1)
      sa[curr].link = q;
    else {
      sa[++idx] = {sa[q].link, 0, sa[p].len + 1, sa[q].next};
      sa[q].link = sa[curr].link = idx;
      while (p != -1 && sa[p].next[ch - 'a'] == q)
        sa[p].next[ch - 'a'] = idx, p = sa[p].link;
    }
  }
  last = curr;
}
vector<int> adj[maxn * 2];
void pre_dfs(int ver) {
  for (auto i : adj[ver]) {
    pre_dfs(i);
    sa[ver].cnt += sa[i].cnt;
  }
}
void extend(int &pos, int &len, char ch) {
  while (pos != -1 && !sa[pos].next.count(ch - 'a')) {
    pos = sa[pos].link;
    len = sa[pos].len;
  }
  if (pos == -1)
    pos = 0, len = 0;
  else {
    len++;
    pos = sa[pos].next[ch - 'a'];
  }
}
bool used[maxn];
vector<int> v;
void solve() {
  init_sa();
  for (auto i : s) extend_sa(i);
  for (int i = 0; i <= idx; i++)
    if (sa[i].link != -1) adj[sa[i].link].push_back(i);
  pre_dfs(0);
  while (q--) {
    string t;
    cin >> t;
    long long ans = 0;
    int pos = 0, len = 0;
    for (auto i : t) {
      extend(pos, len, i);
      if (len >= (int)t.size()) {
        while (sa[pos].link != 0 && sa[sa[pos].link].len >= (int)t.size())
          pos = sa[pos].link;
        if (!used[pos]) {
          v.push_back(pos);
          used[pos] = true;
        }
      }
    }
    for (auto i : t) {
      extend(pos, len, i);
      if (len >= (int)t.size()) {
        while (sa[pos].link != 0 && sa[sa[pos].link].len >= (int)t.size())
          pos = sa[pos].link;
        if (!used[pos]) {
          v.push_back(pos);
          used[pos] = true;
        }
      }
    }
    for (auto i : v) ans += sa[i].cnt, used[i] = false;
    v.clear();
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
