#include <bits/stdc++.h>
using namespace std;
clock_t __stt;
inline void TStart() { __stt = clock(); }
inline void TReport() {
  printf("\nTaken Time : %.3lf sec\n",
         (double)(clock() - __stt) / CLOCKS_PER_SEC);
}
template <typename T>
T MIN(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
T MAX(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
T ABS(T a) {
  return a > 0 ? a : (-a);
}
template <typename T>
void UMIN(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
void UMAX(T &a, T b) {
  if (b > a) a = b;
}
struct node {
  node *nxt[26], *fa;
  int mxv, rsz, lst;
  void init() {
    lst = -1;
    mxv = 0;
    fa = 0;
    rsz = 0;
    memset(nxt, 0, sizeof(nxt));
  }
  int mnv() { return fa ? (fa->mxv + 1) : 0; }
} * last, *root;
vector<node *> ns;
void extend(int v) {
  node *p = last, *np = new node;
  np->init();
  ns.push_back(np);
  np->mxv = p->mxv + 1;
  for (; p && !p->nxt[v]; p = p->fa) p->nxt[v] = np;
  if (!p)
    np->fa = root;
  else {
    node *q = p->nxt[v];
    if (q->mxv == p->mxv + 1) {
      np->fa = q;
    } else {
      node *nq = new node;
      ns.push_back(nq);
      nq->init();
      nq->mxv = p->mxv + 1;
      memcpy(nq->nxt, q->nxt, sizeof(q->nxt));
      nq->fa = q->fa;
      q->fa = np->fa = nq;
      for (; p && p->nxt[v] == q; p = p->fa) p->nxt[v] = nq;
    }
  }
  last = np;
}
bool cmp(node *A, node *B) { return A->mxv < B->mxv; }
char s[1000005], t[1000005];
int n, q;
int main() {
  int i, j, k;
  scanf("%s", s);
  n = strlen(s);
  last = root = new node;
  ns.resize(1, root);
  root->init();
  for (i = 0; i < n; ++i) {
    extend(s[i] - 'a');
  }
  sort(ns.begin(), ns.end(), cmp);
  node *cur = root;
  for (i = 0; i < n; ++i) {
    cur = cur->nxt[s[i] - 'a'];
    ++cur->rsz;
  }
  for (i = (int)ns.size() - 1; i > 0; --i) {
    ns[i]->fa->rsz += ns[i]->rsz;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%s", t);
    n = strlen(t);
    int res = 0, len = 0;
    cur = root;
    for (i = 0; i < n; ++i) {
      while (cur != root && !(cur->nxt[t[i] - 'a'])) {
        cur = cur->fa;
        len = cur->mxv;
      }
      if (cur->nxt[t[i] - 'a']) {
        cur = cur->nxt[t[i] - 'a'];
        ++len;
      }
    }
    for (i = 0; i < n; ++i) {
      while (cur->mnv() > n) {
        cur = cur->fa;
        len = cur->mxv;
      }
      if (len >= n && cur->lst != q) {
        res += cur->rsz;
        cur->lst = q;
      }
      while (cur != root && !(cur->nxt[t[i] - 'a'])) {
        cur = cur->fa;
        len = cur->mxv;
      }
      if (cur->nxt[t[i] - 'a']) {
        cur = cur->nxt[t[i] - 'a'];
        ++len;
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
