#include <bits/stdc++.h>
using namespace std;
inline bool cmp(const pair<int, int> &p, const pair<int, int> &q) {
  return (p.first == q.first) ? p.second > q.second : p.first > q.first;
}
struct state {
  int len, link, cnt, num;
  int next[26];
};
state st[1000002 * 2];
int last;
int sz, n;
char str1[1000002];
void ini_sa() {
  sz = 0;
  st[0].len = 0;
  st[0].link = -1;
  for (int i = 0; i < 26; i++) st[0].next[i] = -1;
  ++sz;
}
void sa_insert(int c) {
  int cur = sz++;
  st[cur].len = st[last].len + 1;
  st[cur].cnt = 1;
  for (int i = 0; i < 26; i++) st[cur].next[i] = -1;
  int p;
  for (p = last; (p != -1) && (st[p].next[c] == -1); p = st[p].link)
    st[p].next[c] = cur;
  if (p == -1)
    st[cur].link = 0;
  else {
    int q = st[p].next[c];
    if (st[q].len == (st[p].len + 1)) {
      st[cur].link = q;
    } else {
      int clone = sz++;
      st[clone].len = st[p].len + 1;
      st[clone].cnt = 0;
      memcpy(st[clone].next, st[q].next, sizeof st[clone].next);
      st[clone].link = st[q].link;
      int temp = clone;
      for (; (p != -1) && (st[p].next[c] == q); p = st[p].link) {
        st[p].next[c] = clone;
      }
      st[q].link = st[cur].link = clone;
    }
  }
  last = cur;
}
int b[1000002 << 1];
pair<int, int> A[1000002 << 1];
int main() {
  ini_sa();
  int p;
  scanf("%s", str1);
  n = strlen(str1);
  int L = n;
  for (int i = 0; i < n; i++) {
    sa_insert(str1[i] - 'a');
  }
  for (int i = 0; i < sz; i++) A[i] = make_pair(st[i].len, i);
  sort(A, A + sz, cmp);
  for (int i = 0; i < sz; i++) b[i] = A[i].second;
  for (int i = 0; i < sz - 1; i++)
    if (b[i]) {
      st[st[b[i]].link].cnt += st[b[i]].cnt;
    }
  int q;
  scanf("%d", &q);
  long long track = 0ll, tend = 0ll;
  for (int kk = 0; kk < 26; kk++)
    if (st[0].next[kk] != -1) tend |= (1ll << kk);
  int vis[sz];
  memset(vis, -1, sizeof vis);
  while (q--) {
    scanf("%s", str1);
    L = strlen(str1);
    long long ans = 0ll;
    track = 0ll;
    long long t2end = 0ll;
    for (int i = 0; i < L; i++) t2end |= (1ll << (int)(str1[i] - 'a'));
    if (t2end > tend) {
      printf("0\n");
      continue;
    }
    int v = 0, j = 0, len = 0, mm = 0;
    L += L;
    for (int i = 0; i < L - 1; i++) {
      while (v && (st[v].next[str1[i % (L / 2)] - 'a'] == -1)) {
        v = st[v].link;
        len = st[v].len;
      }
      if (st[v].next[str1[i % (L / 2)] - 'a'] != -1) {
        v = st[v].next[str1[i % (L / 2)] - 'a'];
        len++;
      }
      if (len >= (L >> 1)) {
        while (v && st[st[v].link].len >= (L >> 1)) {
          v = st[v].link;
          len = st[v].len;
        }
        if (vis[v] != q) {
          vis[v] = q;
          ans += st[v].cnt;
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
