#include <bits/stdc++.h>
const int maxn = 1e6 + 10;
const int maxm = 1e5 + 10;
const long long int mod = 1e9 + 7;
const long long int INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n, m;
int cas, tol, T;
struct Sam {
  int node[maxn << 1][27], step[maxn << 1], fa[maxn << 1];
  int dp[maxn << 1], tax[maxn << 1], gid[maxn << 1];
  int vis[maxn << 1];
  int last, sz;
  int newnode() {
    memset(node[++sz], 0, sizeof node[++sz]);
    dp[sz] = step[sz] = fa[sz] = 0;
    return sz;
  }
  void init() {
    sz = 0;
    last = newnode();
  }
  void insert(int k) {
    int p = last, np = last = newnode();
    dp[np] = 1;
    step[np] = step[p] + 1;
    for (; p && !node[p][k]; p = fa[p]) node[p][k] = np;
    if (p == 0) {
      fa[np] = 1;
    } else {
      int q = node[p][k];
      if (step[q] == step[p] + 1) {
        fa[np] = q;
      } else {
        int nq = newnode();
        memcpy(node[nq], node[q], sizeof(node[q]));
        fa[nq] = fa[q];
        step[nq] = step[p] + 1;
        fa[np] = fa[q] = nq;
        for (; p && node[p][k] == q; p = fa[p]) node[p][k] = nq;
      }
    }
  }
  void handle() {
    for (int i = 0; i <= sz; i++) tax[i] = 0;
    for (int i = 1; i <= sz; i++) tax[step[i]]++;
    for (int i = 1; i <= sz; i++) tax[i] += tax[i - 1];
    for (int i = 1; i <= sz; i++) gid[tax[step[i]]--] = i;
    for (int i = sz; i >= 1; i--) {
      int u = gid[i];
      dp[fa[u]] += dp[u];
    }
  }
  int solve(char *s, int len, int id) {
    int p = 1, res = 0;
    int ans = 0;
    for (int i = 1; i <= len + len; i++) {
      int k = s[i] - 'a' + 1;
      while (p && !node[p][k]) {
        p = fa[p];
        res = step[p];
      }
      if (p == 0) {
        p = 1;
        res = 0;
      } else {
        p = node[p][k];
        res++;
        if (res >= len) {
          int tmp = p;
          while (tmp && vis[tmp] != id &&
                 !(step[fa[tmp]] + 1 <= len && len <= step[tmp])) {
            vis[tmp] = id;
            tmp = fa[tmp];
          }
          if (vis[tmp] != id) {
            vis[tmp] = id;
            ans += dp[tmp];
          }
        }
      }
    }
    return ans;
  }
} sam;
char s[maxn], t[maxn << 1];
int main() {
  scanf("%s", s + 1);
  int slen = strlen(s + 1);
  sam.init();
  for (int i = 1; i <= slen; i++) {
    sam.insert(s[i] - 'a' + 1);
  }
  sam.handle();
  scanf("%d", &T);
  for (int tt = 1; tt <= T; tt++) {
    scanf("%s", t + 1);
    int tlen = strlen(t + 1);
    for (int i = 1; i <= tlen; i++) {
      t[i + tlen] = t[i];
    }
    t[tlen + tlen + 1] = '\0';
    int ans = sam.solve(t, tlen, tt);
    printf("%d\n", ans);
  }
  return 0;
}
