#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct node {
  int son[26], len, fail;
} tr[N * 2];
int sz = 1, lst = 1, id[N * 2], tot[N * 2], Right[N * 2];
void insert(int x) {
  int np = ++sz, p = lst;
  lst = np;
  tr[np].len = tr[p].len + 1;
  while (p && !tr[p].son[x]) tr[p].son[x] = np, p = tr[p].fail;
  if (!p)
    tr[np].fail = 1;
  else {
    int q = tr[p].son[x];
    if (tr[q].len == tr[p].len + 1)
      tr[np].fail = q;
    else {
      int nq = ++sz;
      tr[nq] = tr[q];
      tr[nq].len = tr[p].len + 1;
      tr[np].fail = tr[q].fail = nq;
      while (p && tr[p].son[x] == q) tr[p].son[x] = nq, p = tr[p].fail;
    }
  }
}
int n, Q;
void init() {
  for (int i = 1; i <= sz; i++) tot[tr[i].len]++;
  for (int i = 1; i <= n; i++) tot[i] += tot[i - 1];
  for (int i = 1; i <= sz; i++) id[tot[tr[i].len]--] = i;
  for (int i = sz; i; i--) {
    int x = id[i], fa = tr[x].fail;
    Right[fa] += Right[x];
  }
}
char s[N * 2];
int vis[N * 2];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) insert(s[i] - 'a');
  for (int i = 1, now = 1; i <= n; i++) {
    now = tr[now].son[s[i] - 'a'];
    Right[now]++;
  }
  init();
  scanf("%d", &Q);
  int sign = 0;
  while (Q--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (int i = 1; i < n; i++) s[n + i] = s[i];
    s[2 * n] = 0;
    long long ans = 0;
    ++sign;
    for (int i = 1, now = 1, len = 0; i < 2 * n; i++) {
      int j = s[i] - 'a';
      while (now && !tr[now].son[j]) now = tr[now].fail, len = tr[now].len;
      if (!now)
        now = 1, len = 0;
      else
        now = tr[now].son[j], len++;
      while (tr[now].fail && tr[tr[now].fail].len >= n)
        now = tr[now].fail, len = tr[now].len;
      if (len >= n) {
        if (vis[now] != sign) ans += Right[now];
        vis[now] = sign;
      }
    }
    cout << ans << "\n";
  }
}
