#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const int Alpha = 27;
struct State {
  int visited;
  int Link, Len;
  int Next[Alpha];
  State() {
    visited = 0;
    Link = Len = 0;
    memset(Next, -1, sizeof Next);
  }
};
int Dp[2 * N];
class SuffixAutmaton {
 public:
  int Sz, Last;
  vector<State> st;
  vector<bool> Terminal;
  void init(int n) {
    st.clear();
    st.resize(2 * n);
    Terminal.clear();
    Terminal.resize(2 * n);
    st[0].Len = 0;
    st[0].Link = -1;
    Sz = 1;
    Last = 0;
  }
  void Add(char ch) {
    int c = ch - 'a';
    int Cur = Sz++;
    st[Cur].Len = st[Last].Len + 1;
    int p = Last;
    while (p != -1 && st[p].Next[c] == -1) {
      st[p].Next[c] = Cur;
      p = st[p].Link;
    }
    if (p == -1) {
      st[Cur].Link = 0;
    } else {
      int q = st[p].Next[c];
      if (st[p].Len + 1 == st[q].Len) {
        st[Cur].Link = q;
      } else {
        int Clone = Sz++;
        st[Clone].Len = st[p].Len + 1;
        st[Clone].Link = st[q].Link;
        for (int i = 0; i < Alpha; i++) st[Clone].Next[i] = st[q].Next[i];
        while (p != -1 && st[p].Next[c] == q) {
          st[p].Next[c] = Clone;
          p = st[p].Link;
        }
        st[q].Link = st[Cur].Link = Clone;
      }
    }
    Last = Cur;
  }
  void GetTerminal() {
    int p = Last;
    while (p > 0) {
      Terminal[p] = 1;
      p = st[p].Link;
    }
  }
  void Build(string& s) {
    init(s.size());
    for (auto i : s) Add(i);
    GetTerminal();
  }
  void getPaths(int u) {
    if (Dp[u]) return;
    Dp[u] = Terminal[u];
    for (int i = 0; i < Alpha; i++)
      if (st[u].Next[i] + 1) {
        getPaths(st[u].Next[i]);
        Dp[u] += Dp[st[u].Next[i]];
      }
  }
  int Solve(string& s, int test) {
    int u = 0;
    int Res = 0;
    int length = s.size();
    s += s;
    int j = 0;
    for (int i = 0; i < length; i++) {
      while (j < i + length) {
        if (st[u].Next[s[j] - 'a'] == -1) break;
        u = st[u].Next[s[j++] - 'a'];
      }
      if (j - i == length && st[u].visited != test) {
        Res += Dp[u];
        st[u].visited = test;
      }
      int newLength = j - i - 1;
      if (u && st[st[u].Link].Len >= newLength) u = st[u].Link;
    }
    return Res;
  }
} SA;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  SA.Build(s);
  SA.getPaths(0);
  int T;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    string q;
    cin >> q;
    cout << SA.Solve(q, i) << '\n';
  }
  return 0;
}
