#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
const int SIZE = maxn << 1;
char str[maxn];
struct SAM {
  int nxt[SIZE][26], par[SIZE], len[SIZE];
  int cur[SIZE], pos[SIZE], g[SIZE], vis[SIZE], S[SIZE];
  int root, last, tol, top;
  int newNode(int x) {
    len[tol] = x;
    par[tol] = -1;
    memset(nxt[tol], -1, sizeof nxt[tol]);
    return tol++;
  }
  void Init() {
    root = tol = 0;
    last = newNode(0);
  }
  void add(int k) {
    int p = last;
    int np = newNode(len[p] + 1);
    while (p != -1 && nxt[p][k] == -1) {
      nxt[p][k] = np;
      p = par[p];
    }
    if (p == -1)
      par[np] = root;
    else {
      int q = nxt[p][k];
      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][k] == q) {
          nxt[p][k] = nq;
          p = par[p];
        }
      }
    }
    last = np;
  }
  void ins(char s[]) {
    for (int i = 0; s[i]; i++) {
      add(s[i] - 'a');
    }
  }
  void get_right(char s[]) {
    memset(cur, 0, sizeof cur);
    memset(g, 0, sizeof g);
    memset(vis, 0, sizeof vis);
    for (int i = 0; i < tol; i++) cur[len[i]]++;
    for (int i = 0; i < tol; i++) cur[i] += cur[i - 1];
    for (int i = 0; i < tol; i++) pos[--cur[len[i]]] = i;
    int now = root;
    for (int i = 0; s[i]; i++) g[now = nxt[now][s[i] - 'a']]++;
    for (int i = tol - 1; i >= 0; i--) {
      int u = pos[i];
      g[par[u]] += g[u];
    }
  }
  int Count(char s[]) {
    int now = root, maxlen = 0;
    int l = strlen(s), ans = 0;
    top = 0;
    for (int i = 0; i < l; i++) {
      s[i + l] = s[i];
    }
    s[l << 1] = '\0';
    for (int i = 0, k; s[i]; i++) {
      k = s[i] - 'a';
      if (nxt[now][k] != -1) {
        maxlen++;
        now = nxt[now][k];
        int t = now;
        while (par[t] != -1 && len[par[t]] >= l) t = par[t];
        if (maxlen >= l && !vis[t]) {
          ans += g[t];
          vis[t] = 1;
          S[++top] = t;
        }
      } else {
        while (now != -1 && nxt[now][k] == -1) now = par[now];
        if (now == -1) {
          now = root;
          maxlen = 0;
        } else {
          maxlen = len[now] + 1;
          now = nxt[now][k];
          int t = now;
          while (par[t] != -1 && len[par[t]] >= l) t = par[t];
          if (maxlen >= l && !vis[t]) {
            ans += g[t];
            vis[t] = 1;
            S[++top] = t;
          }
        }
      }
    }
    while (top) vis[S[top--]] = 0;
    return ans;
  }
} sam;
int main() {
  int n;
  while (scanf("%s", str) != EOF) {
    sam.Init();
    sam.ins(str);
    sam.get_right(str);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%s", str);
      printf("%d\n", sam.Count(str));
    }
  }
  return 0;
}
