#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
struct node {
  int Next[26], len, fa;
} Tree[maxn];
int n, m, N, last = 1, tot = 1, f[maxn], Begin[maxn], Next[maxn], To[maxn], e;
bool vis[maxn];
char s[maxn];
vector<int> Rub;
inline void add(int u, int v) {
  To[++e] = v;
  Next[e] = Begin[u];
  Begin[u] = e;
}
inline void Extand(int c) {
  int cur = ++tot;
  f[cur] = 1;
  Tree[cur].len = Tree[last].len + 1;
  int p = last;
  last = cur;
  while (p && !Tree[p].Next[c]) {
    Tree[p].Next[c] = cur;
    p = Tree[p].fa;
  }
  if (!p) {
    Tree[cur].fa = 1;
    return;
  }
  int q = Tree[p].Next[c];
  if (Tree[p].len + 1 == Tree[q].len)
    Tree[cur].fa = q;
  else {
    int clone = ++tot;
    Tree[clone] = Tree[q];
    Tree[clone].len = Tree[p].len + 1;
    while (p && Tree[p].Next[c] == q) {
      Tree[p].Next[c] = clone;
      p = Tree[p].fa;
    }
    Tree[cur].fa = Tree[q].fa = clone;
  }
}
inline void DFS(int u) {
  for (int i = Begin[u]; i; i = Next[i]) {
    int v = To[i];
    DFS(v);
    f[u] += f[v];
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) Extand(s[i] - 'a');
  for (int i = (2), _end_ = (tot); i <= _end_; ++i) add(Tree[i].fa, i);
  DFS(1);
  scanf("%d", &m);
  while (m--) {
    scanf("%s", s + 1);
    N = strlen(s + 1);
    for (int i = (1), _end_ = (N); i <= _end_; ++i) s[i + N] = s[i];
    N += N;
    int ans = 0, p = 1, len = 0;
    for (int i = (1), _end_ = (N - 1); i <= _end_; ++i) {
      int c = s[i] - 'a';
      while (p != 1 && !Tree[p].Next[c]) {
        p = Tree[p].fa;
        len = Tree[p].len;
      }
      if (Tree[p].Next[c]) {
        p = Tree[p].Next[c];
        ++len;
      }
      while (p != 1 && Tree[Tree[p].fa].len >= N / 2) {
        p = Tree[p].fa;
        len = Tree[p].len;
      }
      if (len >= N / 2 && !vis[p]) {
        ans += f[p];
        vis[p] = true;
        Rub.push_back(p);
      }
    }
    for (auto i : Rub) vis[i] = false;
    Rub.clear();
    printf("%d\n", ans);
  }
  return 0;
}
