#include <bits/stdc++.h>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 1000000009;
}
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
}
template <typename T>
inline T const &MAX(T const &a, T const &b) {
  return a > b ? a : b;
}
template <typename T>
inline T const &MIN(T const &a, T const &b) {
  return a < b ? a : b;
}
inline long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000009;
    a = a * a % 1000000009, b >>= 1;
  }
  return ans;
}
inline long long qp(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = a * a % c, b >>= 1;
  }
  return ans;
}
using namespace std;
const unsigned long long ba = 233;
const double eps = 1e-5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1000000 + 10, maxn = 1000000 + 10, inf = 0x3f3f3f3f;
char s[N], p[N];
struct SAM {
  int last, cnt;
  int ch[N << 1][26], fa[N << 1], l[N << 1], sz[N << 1];
  int a[N << 1], c[N << 1];
  void ins(int x) {
    int p = last, np = ++cnt;
    last = np;
    l[np] = l[p] + 1;
    for (; p && !ch[p][x]; p = fa[p]) ch[p][x] = np;
    if (!p)
      fa[np] = 1;
    else {
      int q = ch[p][x];
      if (l[q] == l[p] + 1)
        fa[np] = q;
      else {
        int nq = ++cnt;
        l[nq] = l[p] + 1;
        memcpy(ch[nq], ch[q], sizeof ch[q]);
        fa[nq] = fa[q];
        fa[q] = fa[np] = nq;
        for (; ch[p][x] == q; p = fa[p]) ch[p][x] = nq;
      }
    }
    sz[np] = 1;
  }
  void topo() {
    for (int i = 1; i <= cnt; i++) c[l[i]]++;
    for (int i = 1; i <= cnt; i++) c[i] += c[i - 1];
    for (int i = 1; i <= cnt; i++) a[c[l[i]]--] = i;
  }
  void build() {
    scanf("%s", s + 1);
    cnt = last = 1;
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++) ins(s[i] - 'a');
    topo();
    for (int i = cnt; i; i--) sz[fa[a[i]]] += sz[a[i]];
  }
} sam;
int fail[N];
int getfail() {
  int k = -1;
  fail[0] = -1;
  for (int i = 1; p[i]; i++) {
    while (k > -1 && p[k + 1] != p[i]) k = fail[k];
    if (p[k + 1] == p[i]) k++;
    fail[i] = k;
  }
  return strlen(p) - 1 - fail[strlen(p) - 1];
}
int main() {
  sam.build();
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s", p);
    int x = getfail(), len = strlen(p);
    if (len % x == 0)
      x -= 2;
    else
      x = len - 2;
    int now = 1, le = 0;
    long long ans = 0;
    for (int j = 0; j < len; j++) {
      while (now && !sam.ch[now][p[j] - 'a'])
        now = sam.fa[now], le = sam.l[now];
      if (!now)
        now = 1, le = 0;
      else
        now = sam.ch[now][p[j] - 'a'], le++;
    }
    if (le == len) ans += sam.sz[now];
    for (int j = 0; j <= x; j++) {
      while (now && !sam.ch[now][p[j] - 'a'])
        now = sam.fa[now], le = sam.l[now];
      if (!now)
        now = 1, le = 0;
      else {
        now = sam.ch[now][p[j] - 'a'];
        le++;
        while (now && sam.l[sam.fa[now]] + 1 > len)
          now = sam.fa[now], le = sam.l[now];
        if (!now) now = 1, le = 0;
      }
      if (le >= len) ans += sam.sz[now];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
