#include <bits/stdc++.h>
template <typename Tp>
Tp Max(const Tp &a, const Tp &b) {
  return a > b ? a : b;
}
template <typename Tp>
Tp Min(const Tp &a, const Tp &b) {
  return a < b ? a : b;
}
template <typename Tp>
void Read(Tp &x) {
  Tp in = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    in = in * 10 + ch - '0';
    ch = getchar();
  }
  x = in * f;
}
const int SN = 2000000 + 10;
int ch[SN][26], len[SN], fail[SN], TIME, last, S, n, N, M;
int d[SN], right[SN], vis[SN], sta[SN], top;
char s[SN];
void Insert(int x) {
  int now = ++TIME, p = last, to = s[x] - 'a';
  last = now, len[now] = len[p] + 1;
  for (; p && !ch[p][to]; p = fail[p]) ch[p][to] = now;
  if (!p)
    fail[now] = S;
  else {
    int q = ch[p][to];
    if (len[q] == len[p] + 1) {
      fail[now] = q;
      return;
    }
    int Nq = ++TIME;
    memcpy(ch[Nq], ch[q], sizeof ch[q]);
    fail[Nq] = fail[q], len[Nq] = len[p] + 1;
    fail[q] = fail[now] = Nq;
    for (; p && ch[p][to] == q; p = fail[p]) ch[p][to] = Nq;
  }
}
int main() {
  last = S = TIME = 1;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) Insert(i);
  for (int i = 1; i <= TIME; i++) d[fail[i]]++;
  for (int now = S, i = 1; i <= n; i++) now = ch[now][s[i] - 'a'], right[now]++;
  for (int i = 1; i <= TIME; i++)
    if (!d[i]) sta[++top] = i;
  while (top) {
    int now = sta[top--];
    right[fail[now]] += right[now];
    if (!(--d[fail[now]])) sta[++top] = fail[now];
  }
  Read(N);
  while (N--) {
    scanf("%s", s + 1);
    M = strlen(s + 1);
    n = M;
    for (int i = 1; i < M; i++) s[++n] = s[i];
    int now = S, max = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      int to = s[i] - 'a';
      if (ch[now][to])
        now = ch[now][to], max++;
      else {
        while (now && !ch[now][to]) now = fail[now];
        if (!now)
          now = S, max = 0;
        else if (ch[now][to])
          max = len[now] + 1, now = ch[now][to];
      }
      if (max == M) {
        if (vis[now] != N + 1) ans += right[now], vis[now] = N + 1;
        max--;
        if (max <= len[fail[now]]) now = fail[now];
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
