#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e6 + 4;
const int maxm = 1e3 + 4;
const double pi = acos(-1.0);
struct SuffixAutoMachine {
  int trans[maxn][26], maxlen[maxn], link[maxn], cnt, lst;
  int times[maxn], in[maxn], mark[maxn];
  inline int id(char x) { return x - 'a'; }
  void newNode() {
    cnt++;
    memset(trans[cnt], -1, sizeof trans[cnt]);
    link[cnt] = -1;
    times[cnt] = 0;
    return;
  }
  void insert(int id) {
    newNode();
    maxlen[cnt] = maxlen[lst] + 1;
    times[cnt] = 1;
    int u = lst;
    while (u != -1 && trans[u][id] == -1) {
      trans[u][id] = cnt;
      u = link[u];
    }
    if (u == -1) {
      link[cnt] = 0;
      lst = cnt;
      return;
    }
    int q = trans[u][id];
    if (maxlen[q] == maxlen[u] + 1) {
      link[cnt] = q;
      lst = cnt;
      return;
    }
    int cur = cnt, sq = cnt + 1;
    newNode();
    maxlen[sq] = maxlen[u] + 1;
    memcpy(trans[sq], trans[q], sizeof trans[q]);
    link[sq] = link[q];
    link[q] = sq;
    link[cur] = sq;
    lst = cur;
    times[sq] = 0;
    while (u != -1 && trans[u][id] == q) {
      trans[u][id] = sq;
      u = link[u];
    }
    return;
  }
  void init() {
    cnt = -1;
    newNode();
    maxlen[0] = 0;
    lst = 0;
    memset(in, 0, sizeof in);
    memset(mark, -1, sizeof mark);
  }
  void construct(char* s) {
    init();
    for (int i = 0; s[i]; ++i) insert(id(s[i]));
    for (int i = 1; i <= cnt; ++i) in[link[i]]++;
    queue<int> q;
    for (int i = 1; i <= cnt; ++i)
      if (!in[i]) q.push(i);
    while (q.size()) {
      int top = q.front();
      q.pop();
      if (top == 0) continue;
      times[link[top]] += times[top];
      if (--in[link[top]] == 0) q.push(link[top]);
    }
  }
  long long match(int idx, char* s, int n) {
    for (int i = 0; i < n; ++i) s[i + n] = s[i];
    s[n + n] = 0;
    long long ret = 0;
    int len = 0, cur = 0;
    for (int i = 0; s[i]; ++i) {
      if (cur != 0) {
        int bef = link[cur];
        if (maxlen[bef] == n - 1) {
          cur = bef, len = n - 1;
        }
      }
      int nxt = id(s[i]);
      while (cur != 0 && trans[cur][nxt] == -1) {
        cur = link[cur];
        len = maxlen[cur];
      }
      if (trans[cur][nxt] != -1) {
        cur = trans[cur][nxt];
        len++;
      }
      if (len >= n && mark[cur] != idx) {
        mark[cur] = idx;
        ret += times[cur];
      }
    }
    return ret;
  }
} SAM;
char s[maxn];
int n;
int main() {
  int ik, i, j, k, kase;
  scanf("%s", s);
  SAM.construct(s);
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%s", s);
    printf("%lld\n", SAM.match(i, s, strlen(s)));
  }
  return 0;
}
