#include <bits/stdc++.h>
using namespace std;
char S[1000010 << 1];
int N, Q;
namespace SAM {
int son[1000010 << 1][27], len[1000010 << 1], par[1000010 << 1],
    size[1000010 << 1];
int last, sz = 1, root = 1;
inline void Init() { last = root; }
inline void Extend(int c) {
  int cur = ++sz, p = last;
  len[cur] = len[p] + 1;
  size[cur] = 1;
  while (p && !son[p][c]) son[p][c] = cur, p = par[p];
  if (!p)
    par[cur] = root;
  else {
    int q = son[p][c];
    if (len[p] + 1 == len[q])
      par[cur] = q;
    else {
      int nq = ++sz;
      memcpy(son[nq], son[q], sizeof(son[nq]));
      len[nq] = len[p] + 1;
      par[nq] = par[q];
      while (p && son[p][c] == q) son[p][c] = nq, p = par[p];
      par[cur] = par[q] = nq;
    }
  }
  last = cur;
}
inline void Build() {
  Init();
  for (int i = 1; i <= N; i++) Extend(S[i] - 'a' + 1);
}
int st[1000010], id[1000010 << 1];
inline void Pre() {
  for (int i = 1; i <= sz; i++) st[len[i]]++;
  for (int i = 1; i <= N; i++) st[i] += st[i - 1];
  for (int i = 1; i <= sz; i++) id[st[len[i]]--] = i;
  for (int i = sz; i >= 1; i--) size[par[id[i]]] += size[id[i]];
}
int flag[1000010 << 1];
inline void Query() {
  int now = root, L = 0, ans = 0;
  for (int i = 1; i <= N + N; i++) {
    int c = S[i] - 'a' + 1;
    if (son[now][c])
      L++, now = son[now][c];
    else {
      while (now && !son[now][c]) now = par[now];
      if (!now)
        now = root, L = 0;
      else
        L = len[now] + 1, now = son[now][c];
    }
    if (i > N && L >= N) {
      int tmp = now;
      while (tmp && !(N >= len[par[tmp]] + 1 && N <= len[tmp])) tmp = par[tmp];
      if (!tmp) tmp = root;
      if (flag[tmp] != Q + 1) ans += size[tmp], flag[tmp] = Q + 1;
    }
  }
  printf("%d\n", ans);
}
}  // namespace SAM
using namespace SAM;
int main() {
  scanf("%s", S + 1);
  N = strlen(S + 1);
  SAM::Build();
  SAM::Pre();
  scanf("%d", &Q);
  while (Q--) {
    scanf("%s", S + 1);
    N = strlen(S + 1);
    for (int i = 1; i <= N; i++) S[N + i] = S[i];
    SAM::Query();
  }
  return 0;
}
