#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int link[N], nxt[N][26], len[N], in[N], cnt = 1, las = 1;
char s[N];
map<int, bool> vis;
long long num[N];
void insert(int c) {
  int cur = ++cnt, p = las;
  len[cur] = len[p] + 1;
  las = cur;
  for (; p && nxt[p][c] == 0; p = link[p]) nxt[p][c] = cur;
  if (!p)
    link[cur] = 1;
  else {
    int q = nxt[p][c];
    if (len[p] == len[q] - 1)
      link[cur] = q;
    else {
      int clone = ++cnt;
      len[clone] = len[p] + 1;
      link[clone] = link[q];
      link[q] = link[cur] = clone;
      memcpy(nxt[clone], nxt[q], sizeof(nxt[q]));
      for (; nxt[p][c] == q; p = link[p]) nxt[p][c] = clone;
    }
  }
  num[cur] = 1;
}
void topu() {
  queue<int> q;
  for (int i = 1; i <= cnt; i++) in[link[i]]++;
  for (int i = 1; i <= cnt; i++)
    if (!in[i]) q.push(i);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    int u = link[now];
    if (--in[u] == 0) q.push(u);
    num[u] += num[now];
  }
}
int main() {
  scanf("%s", s + 1);
  for (int i = 1, l = strlen(s + 1); i <= l; i++) insert(s[i] - 'a');
  topu();
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s + 1);
    int l = strlen(s + 1);
    for (int i = 1; i <= l; i++) s[i + l] = s[i];
    l <<= 1;
    vis.clear();
    long long ans = 0;
    for (int i = 1, match = 0, now = 1, last = s[1] - 'a'; i < l; i++) {
      int c = s[i] - 'a';
      last = c;
      int next = nxt[now][c];
      if (!next) {
        while (now && !next) now = link[now], next = nxt[now][c];
        if (!now)
          match = 0, now = 1;
        else
          match = len[now] + 1, now = next;
      } else {
        match++;
        now = next;
      }
      if (match >= l / 2) {
        while (now && len[link[now]] >= l / 2) now = link[now];
        if (vis.count(now))
          continue;
        else
          vis[now] = true;
        ans += num[now];
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
