#include <bits/stdc++.h>
using namespace std;
const int P(29), N(1000010);
int tail, t, n, m, p, len, h;
set<int> ha;
int g[2 * N][26];
vector<int> link[2 * N];
string s;
int b[N];
int cnt[2 * N], fa[2 * N], l[2 * N];
void add(int c) {
  int p = tail, np = ++t;
  ++cnt[np];
  l[np] = l[p] + 1;
  for (; p && !g[p][c]; p = fa[p]) g[p][c] = np;
  tail = np;
  if (!p)
    fa[np] = 1;
  else if (l[p] + 1 == l[g[p][c]])
    fa[np] = g[p][c];
  else {
    int q = g[p][c], r = ++t;
    memcpy(g[r], g[q], sizeof(g[q]));
    fa[r] = fa[q];
    l[r] = l[p] + 1;
    fa[q] = fa[np] = r;
    for (; p && g[p][c] == q; p = fa[p]) g[p][c] = r;
  }
}
void dfs(int x) {
  for (int i = int(0); i < int(link[x].size()); ++i) {
    dfs(link[x][i]);
    cnt[x] += cnt[link[x][i]];
  }
}
int main() {
  b[0] = 1;
  for (int i = int(1); i < int(N); ++i) b[i] = b[i - 1] * P;
  cin >> s;
  n = s.size();
  tail = t = 1;
  for (int i = int(0); i < int(n); ++i) add(s[i] - 'a');
  for (int i = int(2); i < int(t + 1); ++i) link[fa[i]].push_back(i);
  dfs(1);
  for (cin >> m; m; --m) {
    cin >> s;
    n = s.size();
    s = s + s;
    p = 0;
    len = 0;
    h = 0;
    long long ans = 0;
    ha.clear();
    for (int i = int(0); i < int(2 * n - 1); ++i) {
      if (p == 0) p = 1;
      for (; p != 1 && !g[p][s[i] - 'a']; p = fa[p])
        ;
      len = min(len, l[p]);
      p = g[p][s[i] - 'a'];
      if (p) ++len;
      h = h * P + s[i] - 'a' + 1;
      if (i >= n) h -= (s[i - n] - 'a' + 1) * b[n];
      if (len == n) {
        if (!ha.count(h)) {
          ha.insert(h);
          ans += cnt[p];
        }
        if (len == l[fa[p]] + 1) p = fa[p];
        --len;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
