#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100, M = 2 * N;
char str[N];
string str2;
int n, last = 1, tot = 1;
int h[M], ne[M], e[M], idx;
long long f[M];
bool st[M];
int recover[M], cnt;
struct node {
  int fa, len;
  int ch[26];
} tr[M];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
void dfs(int u) {
  for (int i = h[u]; ~i; i = ne[i]) {
    int j = e[i];
    dfs(j);
    f[u] += f[j];
  }
}
void extend(int c) {
  int p = last, np = last = ++tot;
  tr[np].len = tr[p].len + 1;
  f[tot] = 1;
  for (; p && !tr[p].ch[c]; p = tr[p].fa) tr[p].ch[c] = np;
  if (!p)
    tr[np].fa = 1;
  else {
    int q = tr[p].ch[c];
    if (tr[q].len == tr[p].len + 1)
      tr[np].fa = q;
    else {
      int nq = ++tot;
      tr[nq] = tr[q], tr[nq].len = tr[p].len + 1;
      tr[np].fa = tr[q].fa = nq;
      for (; p && tr[p].ch[c] == q; p = tr[p].fa) tr[p].ch[c] = nq;
    }
  }
}
int main() {
  scanf("%s", str), scanf("%d", &n);
  for (int i = 0; str[i]; i++) extend(str[i] - 'a');
  memset(h, -1, sizeof h);
  for (int i = 2; i <= tot; i++) add(tr[i].fa, i);
  dfs(1);
  for (int i = 1; i <= n; i++) {
    cin >> str2;
    cnt = 0;
    int len = str2.length();
    str2 = str2 + str2;
    int l = 0, r = 0, pos = 1, res = 0;
    while (l <= len - 1) {
      while (tr[pos].ch[str2[r] - 'a'] && r - l + 1 <= len) {
        pos = tr[pos].ch[str2[r] - 'a'], r++;
      }
      if (r - l + 1 == len + 1 && !st[pos]) {
        res += f[pos];
        st[pos] = true;
        recover[++cnt] = pos;
      }
      l++;
      if (r - l + 1 == tr[tr[pos].fa].len + 1) {
        pos = tr[pos].fa;
      }
      if (r <= 2 * len - 1) {
        while (pos != 1 && !tr[pos].ch[str2[r] - 'a']) {
          pos = tr[pos].fa;
          int tem = tr[pos].len;
          l = r - tem;
        }
      }
    }
    for (int i = 1; i <= cnt; i++) st[recover[i]] = false;
    printf("%d\n", res);
  }
  return 0;
}
