#include <bits/stdc++.h>
using namespace std;
long double esp = 1e-11;
const long double PI = acos((long double)-1);
const long long int INF = 0x3f3f3f3fll;
const int MOD = 1000000007ll;
const int maxn = 1010100;
int pa[1010000 << 1], son[1010000 << 1][26], Right[1010000 << 1];
int Max[1010000 << 1], cnt, root, last;
inline int Newnode(int _Max) {
  ++cnt;
  memset(son[cnt], 0, sizeof(son[cnt]));
  Max[cnt] = _Max;
  return cnt;
}
inline void pre() {
  cnt = Max[0] = 0;
  root = last = Newnode(0);
}
inline void SAM(int alp) {
  int np = son[last][alp], u = last, v, nv;
  if (np && Max[np] == Max[last] + 1) {
    last = np;
    return;
  } else
    np = Newnode(Max[last] + 1);
  Right[np] = 1;
  while (u && !son[u][alp]) son[u][alp] = np, u = pa[u];
  if (!u)
    pa[np] = root;
  else {
    v = son[u][alp];
    if (Max[v] == Max[u] + 1)
      pa[np] = v;
    else {
      nv = Newnode(Max[u] + 1);
      Right[nv] = 0;
      memcpy(son[nv], son[v], sizeof(son[v]));
      pa[nv] = pa[v], pa[v] = pa[np] = nv;
      while (u && son[u][alp] == v) son[u][alp] = nv, u = pa[u];
    }
  }
  last = np;
}
int ttopo[1010000 << 1], topo[1010000 << 1], Min[1010000 << 1];
void topology() {
  int maxVal = 0;
  memset(ttopo, 0, sizeof(ttopo));
  for (int i = 1; i <= cnt; i++) maxVal = max(maxVal, Max[i]), ttopo[Max[i]]++;
  for (int i = 1; i <= maxVal; i++) ttopo[i] += ttopo[i - 1];
  for (int i = 1; i <= cnt; i++) topo[ttopo[Max[i]]--] = i;
  for (int i = cnt; i >= 1; i--)
    Right[pa[topo[i]]] += Right[topo[i]], Min[topo[i]] = Max[pa[topo[i]]] + 1;
  Min[1] = 0;
}
char s[maxn], ss[maxn * 2];
void test() {
  pre();
  int len = strlen(s);
  for (int x = 0; x < len; x++) SAM(s[x] - 'a');
  topology();
}
set<long long int> in;
long long int hashp = 751;
long long int hashval[maxn];
long long int hashpow[maxn];
void inithash(char* s, int len) {
  hashval[0] = s[0];
  for (int x = 1; x <= len - 1; x++)
    hashval[x] = (hashval[x - 1] * hashp + s[x]) % MOD;
  hashpow[0] = 1;
  for (int x = 1; x <= len - 1; x++) hashpow[x] = hashpow[x - 1] * hashp % MOD;
}
long long int seghash(int a, int b) {
  if (a == 0) return hashval[b];
  return ((hashval[b] - hashval[a - 1] * hashpow[b - a + 1]) % MOD + MOD) % MOD;
}
int main() {
  int q;
  scanf("%s%d", s, &q);
  test();
  for (int x = 1; x <= q; x++) {
    scanf("%s", ss);
    int t = root, l = 0;
    int len = strlen(ss);
    for (int x = len; x < len * 2 - 1; x++) ss[x] = ss[x - len];
    inithash(ss, len * 2 - 1);
    int las = -1;
    long long int ans = 0;
    in.clear();
    for (int o = len - 1; o <= 2 * len - 2; o++) {
      for (int x = las + 1; x <= o; x++) {
        while (t && son[t][ss[x] - 'a'] == 0) {
          t = pa[t];
          l = Max[t];
        }
        if (!t)
          t = root, l = 0;
        else
          t = son[t][ss[x] - 'a'], l++;
      }
      if (in.find(seghash(o - len + 1, o)) == in.end()) {
        in.insert(seghash(o - len + 1, o));
        if (l < len || t == root)
          ;
        else if (Min[t] <= len) {
          ans += Right[t];
        } else {
          int tp = pa[t];
          while (tp) {
            if (Min[tp] <= len && len <= Max[tp]) {
              ans += Right[tp];
              break;
            }
            tp = pa[tp];
          }
        }
      }
      las = o;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
