#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  register int res = 0, f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * f;
}
int n, m;
char c[2000010];
struct node {
  int tr[26];
  int par, maxl;
} s[2000010];
int ptr = 1, root = 1, last = 1;
int newnode(int l) {
  int k = ++ptr;
  s[k].maxl = l;
  return k;
}
int siz[2000010];
void extend(int k) {
  int p = last;
  int np = newnode(s[p].maxl + 1);
  ++siz[np];
  for (; p && s[p].tr[k] == 0; p = s[p].par) s[p].tr[k] = np;
  if (p == 0)
    s[np].par = root;
  else {
    int q = s[p].tr[k];
    if (s[p].maxl + 1 == s[q].maxl)
      s[np].par = q;
    else {
      int nq = newnode(s[p].maxl + 1);
      memcpy(s[nq].tr, s[q].tr, sizeof(s[q].tr));
      s[nq].par = s[q].par;
      s[q].par = s[np].par = nq;
      for (; p && s[p].tr[k] == q; p = s[p].par) s[p].tr[k] = nq;
    }
  }
  last = np;
  return;
}
int w[2000010], p[2000010];
int vis[2000010], tim = 0;
int main() {
  scanf("%s", c + 1);
  n = strlen(c + 1);
  for (int i = 1; i <= n; ++i) extend(c[i] - 'a');
  for (int i = 1; i <= ptr; ++i) ++w[s[i].maxl];
  for (int i = 1; i <= n; ++i) w[i] += w[i - 1];
  for (int i = ptr; i >= 1; --i) p[w[s[i].maxl]--] = i;
  for (int i = ptr; i >= 1; --i) {
    int k = p[i];
    siz[s[k].par] += siz[k];
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%s", c + 1);
    int l = strlen(c + 1);
    for (int i = l + 1; i < 2 * l; ++i) c[i] = c[i - l];
    ++tim;
    int cur = root, matchlen = 0;
    int ans = 0;
    for (int i = 1; i < 2 * l; ++i) {
      if (s[cur].tr[c[i] - 'a'] != 0) {
        ++matchlen;
        cur = s[cur].tr[c[i] - 'a'];
      } else {
        while (cur && s[cur].tr[c[i] - 'a'] == 0) {
          cur = s[cur].par;
          matchlen = s[cur].maxl;
        }
        if (s[cur].tr[c[i] - 'a'] != 0) {
          ++matchlen;
          cur = s[cur].tr[c[i] - 'a'];
        }
      }
      while (matchlen > l && s[s[cur].par].maxl >= l) cur = s[cur].par;
      if (matchlen >= l && vis[cur] != tim) {
        ans += siz[cur];
        vis[cur] = tim;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
