#include <bits/stdc++.h>
using namespace std;
const int N = 2000100;
int go[N][26], par[N], val[N], endpos[N];
int root = 1, last = 1, tot = 1;
inline void newn(int &x, int v, int *g, int f) {
  x = ++tot, val[x] = v, par[x] = f;
  if (g)
    for (int i = 0, nn = int(26); i < nn; ++i) go[x][i] = g[i];
}
inline void insert(int x) {
  int np;
  newn(np, val[last] + 1, NULL, 0);
  endpos[np] = 1;
  int p = last;
  last = np;
  while (p && go[p][x] == 0) go[p][x] = np, p = par[p];
  if (!p)
    par[np] = root;
  else {
    int q = go[p][x];
    if (val[q] == val[p] + 1)
      par[np] = q;
    else {
      int nq;
      newn(nq, val[p] + 1, go[q], par[q]);
      while (p && go[p][x] == q) go[p][x] = nq, p = par[p];
      par[q] = par[np] = nq;
    }
  }
}
inline void query(string &s, int len) {
  int u = root, l = 0, x, ans = 0;
  static bitset<N> vis;
  vis.reset();
  for (int i = 0, nn = int(s.length()); i < nn; ++i) {
    x = s[i] - 'a';
    while (u && !go[u][x]) u = par[u], l = val[u];
    if (!u) u = root, l = 0;
    if (go[u][x]) u = go[u][x], ++l;
    while (u && val[par[u]] >= len) u = par[u], l = val[u];
    if (l >= len && !vis[u]) vis.set(u), ans += endpos[u];
  }
  printf("%d\n", ans);
}
int main() {
  ios ::sync_with_stdio(false);
  string s;
  cin >> s;
  for (int i = 0, nn = int(s.length()); i < nn; ++i) insert(s[i] - 'a');
  static int ss[N / 2], ord[N];
  for (int i = 1, nn = int(tot); i <= nn; ++i) ++ss[val[i]];
  for (int i = 1, nn = int(val[last]); i <= nn; ++i) ss[i] += ss[i - 1];
  for (int i = 1, nn = int(tot); i <= nn; ++i) ord[ss[val[i]]--] = i;
  for (int i = tot, nn = int(1); i >= nn; --i) {
    int x = ord[i];
    endpos[par[x]] += endpos[x];
  }
  int n;
  cin >> n;
  while (n--) {
    cin >> s;
    int l = s.length();
    for (int i = 0, nn = int(l - 1); i < nn; ++i) s += s[i];
    query(s, l);
  }
  return 0;
}
