#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[(1000000 + 5)];
struct SAM {
  int ch[26], fa, len, size;
  bool is;
} S[(1000000 + 5) * 2];
int lst = 1, num = 1;
int cnt[(1000000 + 5)], q[(1000000 + 5) * 2];
void Insert(int c) {
  int u = lst, v = lst = ++num;
  S[v].len = S[u].len + 1;
  for (; u && !S[u].ch[c]; u = S[u].fa) S[u].ch[c] = v;
  if (!u)
    S[v].fa = 1;
  else {
    int x = S[u].ch[c];
    if (S[x].len == S[u].len + 1)
      S[v].fa = x;
    else {
      int y = ++num;
      S[y] = S[x];
      S[y].len = S[u].len + 1;
      for (; u && S[u].ch[c] == x; u = S[u].fa) S[u].ch[c] = y;
      S[v].fa = S[x].fa = y;
    }
  }
}
void Sort() {
  for (int i = 1; i <= num; ++i) ++cnt[S[i].len];
  for (int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1];
  for (int i = num; i; --i) q[cnt[S[i].len]--] = i;
}
int main() {
  scanf("%s%d", str + 1, &m);
  n = strlen(str + 1);
  for (int i = 1; i <= n; ++i) Insert(str[i] - 'a');
  Sort();
  int u = 1;
  for (int i = 1; i <= n; ++i) {
    u = S[u].ch[str[i] - 'a'];
    S[u].size = 1;
  }
  for (int i = num; i; --i) S[S[q[i]].fa].size += S[q[i]].size;
  while (m--) {
    scanf("%s", str + 1);
    int len = strlen(str + 1), c, u = 1, res = 0;
    long long ans = 0;
    for (int i = 1; i <= len; ++i) {
      c = str[i] - 'a';
      while (u != 1 && !S[u].ch[c]) u = S[u].fa, res = S[u].len;
      if (S[u].ch[c]) u = S[u].ch[c], ++res;
    }
    if (res == len) S[u].is = 1, ans += S[u].size;
    for (int i = 1; i < len; ++i) {
      if (res == len && --res <= S[S[u].fa].len) u = S[u].fa;
      c = str[i] - 'a';
      while (u != 1 && !S[u].ch[c]) u = S[u].fa, res = S[u].len;
      if (S[u].ch[c]) u = S[u].ch[c], ++res;
      if (res == len) {
        if (!S[u].is) ans += S[u].size;
        S[u].is = 1;
      }
    }
    printf("%lld\n", ans);
    u = 1, res = 0;
    for (int i = 1; i <= len; ++i) {
      c = str[i] - 'a';
      while (u != 1 && !S[u].ch[c]) u = S[u].fa, res = S[u].len;
      if (S[u].ch[c]) u = S[u].ch[c], ++res;
      S[u].is = 0;
    }
    for (int i = 1; i < len; ++i) {
      if (res == len && --res <= S[S[u].fa].len) u = S[u].fa;
      c = str[i] - 'a';
      while (u != 1 && !S[u].ch[c]) u = S[u].fa, res = S[u].len;
      if (S[u].ch[c]) u = S[u].ch[c], ++res;
      S[u].is = 0;
    }
  }
  return 0;
}
