#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int node = maxn * 2;
char str[maxn * 2];
struct SAM {
  int nxt[node][26];
  int par[node];
  int len[node];
  int cur[node];
  int pos[node];
  int cnt[node];
  int vis[node];
  int S[node];
  int tol, last, rt, top;
  int newNode(int l) {
    memset(nxt[tol], -1, sizeof nxt[tol]);
    len[tol] = l;
    par[tol] = -1;
    return tol++;
  }
  void init() {
    tol = rt = 0;
    last = newNode(0);
  }
  void add(int c) {
    int p = last;
    int np = newNode(len[p] + 1);
    while (p != -1 && nxt[p][c] == -1) {
      nxt[p][c] = np;
      p = par[p];
    }
    if (p == -1)
      par[np] = rt;
    else {
      int q = nxt[p][c];
      if (len[p] + 1 == len[q])
        par[np] = q;
      else {
        int nq = newNode(len[p] + 1);
        memcpy(nxt[nq], nxt[q], sizeof nxt[q]);
        par[nq] = par[q];
        par[q] = par[np] = nq;
        while (p != -1 && nxt[p][c] == q) {
          nxt[p][c] = nq;
          p = par[p];
        }
      }
    }
    last = np;
  }
  void get_right(char s[]) {
    for (int i = 0; i < tol; i++) cur[i] = cnt[i] = 0;
    for (int i = 0; i < tol; i++) cur[len[i]]++;
    for (int i = 1; i < tol; i++) cur[i] += cur[i - 1];
    for (int i = 0; i < tol; i++) pos[--cur[len[i]]] = i;
    int now = rt;
    for (int i = 0; s[i]; i++) cnt[now = nxt[now][s[i] - 'a']]++;
    for (int i = tol - 1; i >= 0; i--) {
      int u = pos[i];
      cnt[par[u]] += cnt[u];
    }
  }
  int cal(char s[]) {
    int now = rt, maxlen = 0;
    int n = strlen(s);
    for (int i = 0; i < n; i++) {
      s[i + n] = s[i];
    }
    s[2 * n - 1] = '\0';
    top = 0;
    int ans = 0;
    for (int i = 0, c; s[i]; i++) {
      c = s[i] - 'a';
      if (nxt[now][c] != -1) {
        now = nxt[now][c];
        maxlen++;
      } else {
        while (now != -1 && nxt[now][c] == -1) now = par[now];
        if (now == -1) {
          now = rt;
          maxlen = 0;
        } else {
          maxlen = len[now] + 1;
          now = nxt[now][c];
        }
      }
      if (maxlen >= n) {
        while (par[now] != -1 && len[par[now]] + 1 > n) now = par[now];
        if (!vis[now]) {
          ans += cnt[now];
          vis[now] = 1;
          S[++top] = now;
        }
      }
    }
    while (top) vis[S[top--]] = 0;
    return ans;
  }
} gao;
int main() {
  scanf("%s", str);
  gao.init();
  for (int i = 0; str[i]; i++) gao.add(str[i] - 'a');
  gao.get_right(str);
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", str);
    printf("%d\n", gao.cal(str));
  }
  return 0;
}
