#include <bits/stdc++.h>
using namespace std;
const int MAXM = 2e6 + 5;
struct SAM {
  int Go[26], fail, Len, Num;
} A[MAXM];
char S[MAXM], T[MAXM];
int tot, Q, Root, Len, LenT, Ord[MAXM], Flag[MAXM];
void BuildSAM() {
  int p;
  p = Root = tot = 1;
  Len = strlen(S + 1);
  for (int i = 1; i <= Len; i++) {
    int ch = S[i] - 'a';
    int np = ++tot;
    A[np].Len = A[p].Len + 1;
    A[np].Num = 1;
    for (; p && !A[p].Go[ch]; p = A[p].fail) A[p].Go[ch] = np;
    if (!p)
      A[np].fail = Root;
    else {
      int q = A[p].Go[ch];
      if (A[p].Len + 1 == A[q].Len)
        A[np].fail = q;
      else {
        int nq = ++tot;
        A[nq] = A[q];
        A[q].fail = A[np].fail = nq;
        A[nq].Len = A[p].Len + 1, A[nq].Num = 0;
        for (; p && A[p].Go[ch] == q; p = A[p].fail) A[p].Go[ch] = nq;
      }
    }
    p = np;
  }
}
bool Cmp(int x, int y) { return A[x].Len > A[y].Len; }
void GetRight() {
  for (int i = 1; i <= tot; i++) Ord[i] = i;
  sort(Ord + 1, Ord + tot + 1, Cmp);
  for (int i = 1; i <= tot; i++) {
    int Now = Ord[i];
    A[A[Now].fail].Num += A[Now].Num;
  }
}
void Solve(int time) {
  scanf("%s", T + 1);
  int LenT = strlen(T + 1);
  for (int i = 1; i <= LenT; i++) T[i + LenT] = T[i];
  int Now = Root, Ans = 0, len = 0;
  for (int i = 1; i <= 2 * LenT; i++) {
    int ch = T[i] - 'a';
    for (; Now && !A[Now].Go[ch]; Now = A[Now].fail)
      ;
    len = (!A[Now].Go[ch]) ? 0 : min(len, A[Now].Len) + 1;
    if (A[Now].Go[ch]) Now = A[Now].Go[ch];
    for (; A[A[Now].fail].Len >= LenT; Now = A[Now].fail, len = A[Now].Len)
      ;
    if (len >= LenT && Flag[Now] != time) Ans += A[Now].Num, Flag[Now] = time;
  }
  printf("%d\n", Ans);
}
int main() {
  scanf("%s", S + 1);
  BuildSAM();
  GetRight();
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) Solve(i);
}
