#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &t) {
  t = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    t = (t << 3) + (t << 1) + c - '0';
    c = getchar();
  }
  t *= f;
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int n, node = 1, lst = 1;
int ch[2000005][26], fa[2000005], len[2000005];
int cnt[2000005], las[2000005];
char s[2000005];
struct edge {
  int v, nxt;
} e[2000005];
int top = 1;
int head[2000005];
void Add_Edge(int u, int v) {
  e[++top] = edge{v, head[u]};
  head[u] = top;
}
void Insert(int c) {
  int f = lst, q = lst = ++node;
  len[q] = len[f] + 1;
  cnt[q]++;
  while (f && !ch[f][c]) ch[f][c] = q, f = fa[f];
  if (f == 0)
    fa[q] = 1;
  else {
    int x = ch[f][c];
    if (len[x] == len[f] + 1)
      fa[q] = x;
    else {
      int p = ++node;
      len[p] = len[f] + 1;
      fa[p] = fa[x];
      fa[x] = fa[q] = p;
      memcpy(ch[p], ch[x], sizeof(ch[x]));
      while (f && ch[f][c] == x) ch[f][c] = p, f = fa[f];
    }
  }
}
void dfs(int u) {
  for (register int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    dfs(v);
    cnt[u] += cnt[v];
  }
}
void solve() {
  for (register int i = 2; i <= node; ++i) Add_Edge(fa[i], i);
  dfs(1);
}
int x, l, m, ans, tim;
void calc() {
  if (l == m && las[x] < tim) {
    ans += cnt[x];
    las[x] = tim;
  }
}
void del() {
  if (l > m && --l == len[fa[x]]) x = fa[x];
}
void Extend(int c) {
  while (x && !ch[x][c]) l = len[x = fa[x]];
  if (ch[x][c]) {
    ++l;
    x = ch[x][c];
  }
}
signed main() {
  int minlen = 0x7f7f7f7f;
  scanf("%s", s + 1);
  for (register int i = 1; s[i]; ++i) Insert(s[i] - 'a');
  solve();
  read(n);
  for (tim = 1; tim <= n; ++tim) {
    scanf("%s", s + 1);
    x = 1, l = 0, ans = 0, m = strlen(s + 1);
    for (register int i = 1; i <= m; ++i) Extend(s[i] - 'a');
    calc();
    for (register int i = 1; i < m; ++i) Extend(s[i] - 'a'), del(), calc();
    write(ans), putchar('\n');
  }
  return 0;
}
