#include <bits/stdc++.h>
long long ans;
int n, t, k, m, len;
char s[2000005];
struct SAM {
  int ch[2000005][26], step[2000005], pre[2000005], cnt, last, a[2000005],
      b[2000005], sz[2000005], u, l;
  int vis[2000005], id;
  inline void init() {
    memset(ch, 0, sizeof ch);
    memset(a, 0, sizeof a);
    memset(b, 0, sizeof b);
    memset(sz, 0, sizeof sz);
    memset(step, 0, sizeof step);
    memset(pre, 0, sizeof pre);
    cnt = last = 1;
    u = 1, l = 0;
  }
  inline int ins(int x) {
    int p = last;
    if (ch[p][x]) {
      int q = ch[p][x];
      if (step[p] + 1 == step[q]) {
        sz[q]++;
        return q;
      }
      int nq = ++cnt;
      step[nq] = step[p] + 1;
      memcpy(ch[nq], ch[q], sizeof ch[q]);
      pre[nq] = pre[q];
      pre[q] = nq;
      while (ch[p][x] == q) ch[p][x] = nq, p = pre[p];
      sz[nq] = 1;
      return nq;
    }
    int np = ++cnt;
    last = cnt;
    step[np] = step[p] + 1;
    sz[np] = 1;
    while (p && !ch[p][x]) ch[p][x] = np, p = pre[p];
    if (!p)
      pre[np] = 1;
    else {
      int q = ch[p][x];
      if (step[q] == step[p] + 1)
        pre[np] = q;
      else {
        int nq = ++cnt;
        step[nq] = step[p] + 1;
        memcpy(ch[nq], ch[q], sizeof ch[q]);
        pre[nq] = pre[q];
        pre[q] = pre[np] = nq;
        while (ch[p][x] == q) ch[p][x] = nq, p = pre[p];
      }
    }
    return np;
  }
  inline void init2() {
    for (int i = (1); i <= (cnt); ++i) a[step[i]]++;
    for (int i = (1); i <= (cnt); ++i) a[i] += a[i - 1];
    for (int i = (1); i <= (cnt); ++i) b[a[step[i]]--] = i;
    for (int i = (cnt); i >= (1); --i) sz[pre[b[i]]] += sz[b[i]];
    return;
  }
  inline void print() {
    for (int i = (1); i <= (cnt); ++i)
      for (int j = (0); j <= (25); ++j)
        if (ch[i][j]) printf("%d --%c--> %d \n", i, j + 'a', ch[i][j]);
    for (int i = (1); i <= (cnt); ++i) printf("pre[%d] = %d \n", i, pre[i]);
  }
  inline void solve() {
    ++id;
    ans = 0;
    int u = 1;
    l = 0;
    for (int i = (1); i <= (m); ++i) {
      while (u && !ch[u][s[i]]) {
        u = pre[u], l = step[u];
      }
      if (!u) {
        u = 1;
        l = 0;
      } else {
        u = ch[u][s[i]];
        ++l;
      }
      if (i >= n) {
        while (l > n) {
          if (step[pre[u]] >= n) {
            u = pre[u];
            l = step[u];
          } else {
            l = n;
          }
        }
        if (l == n) {
          if (vis[u] != id) {
            vis[u] = id;
            ans += sz[u];
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
} sam;
int main() {
  sam.init();
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = (1); i <= (n); ++i) sam.last = sam.ins(s[i] - 'a');
  scanf("%d", &t);
  sam.init2();
  while (t--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (int i = (1); i <= (n); ++i) s[i] -= 'a';
    for (int i = (n + 1); i <= (2 * n - 1); ++i) s[i] = s[i - n];
    m = 2 * n - 1;
    sam.solve();
  }
  return 0;
}
