#include <bits/stdc++.h>
using namespace std;
struct sam {
  int f[2000011];
  int step[2000011];
  int next[2000011][26];
  int end, tail;
  void init() {
    memset(next, -1, sizeof(next));
    f[0] = -1;
    step[0] = 0;
    end = 0;
    tail = 1;
    return;
  }
  void add(int xx) {
    int p, q, np, nq;
    np = tail++;
    step[np] = step[end] + 1;
    p = end;
    end = np;
    for (; p != -1 && next[p][xx] == -1; p = f[p]) {
      next[p][xx] = np;
    }
    if (p == -1) {
      f[np] = 0;
    } else {
      q = next[p][xx];
      if (step[p] + 1 == step[q]) {
        f[np] = q;
      } else {
        nq = tail++;
        memcpy(next[nq], next[q], sizeof(next[q]));
        step[nq] = step[p] + 1;
        f[nq] = f[q];
        f[q] = f[np] = nq;
        for (; p != -1 && next[p][xx] == q; p = f[p]) {
          next[p][xx] = nq;
        }
      }
    }
  }
} sam;
int right0[2000011];
int arr[2000011];
int aarr[2000011];
bool cmp1(int xx, int yy) { return sam.step[xx] < sam.step[yy]; }
long long ans;
char s[1000011];
int len;
int n;
char d[2000011];
int len2;
int mark[2000011];
int q[2000011];
int ll;
int inq[2000011];
void gao(int times) {
  int i, j;
  int len;
  int xx;
  int p, step;
  for (i = 0; i < len2 - 1; i++) {
    d[i + len2] = d[i];
  }
  d[len2 * 2 - 1] = 0;
  len = len2 * 2 - 1;
  ll = 0;
  p = 0;
  step = 0;
  for (i = 0; i < len; i++) {
    xx = d[i] - 'a';
    while (p != 0 && sam.next[p][xx] == -1) {
      p = sam.f[p];
      step = sam.step[p];
    }
    if (sam.next[p][xx] != -1) {
      p = sam.next[p][xx];
      step++;
    }
    if (step >= len2) {
      mark[p] = times;
    }
    if (inq[p] != times) {
      ll++;
      q[ll] = p;
      inq[p] = times;
    }
  }
  for (i = 1; i <= ll; i++) {
    xx = sam.f[q[i]];
    if (xx != 0 && inq[xx] != times) {
      inq[xx] = times;
      ll++;
      q[ll] = xx;
    }
  }
  sort(q + 1, q + 1 + ll, cmp1);
  for (i = ll; i >= 1; i--) {
    xx = q[i];
    if (mark[xx] == times) {
      if (sam.step[xx] < len2) {
        continue;
      }
      if (sam.step[sam.f[xx]] < len2) {
        ans += right0[xx];
      } else {
        mark[sam.f[xx]] = mark[xx];
      }
    }
  }
  return;
}
int main() {
  int i, j, k;
  int p, xx;
  scanf("%s", s);
  len = strlen(s);
  sam.init();
  for (i = 0; i < len; i++) {
    sam.add(s[i] - 'a');
  }
  for (i = 0; i < sam.tail; i++) {
    arr[i] = i;
  }
  sort(arr, arr + sam.tail, cmp1);
  for (i = 0; i < sam.tail; i++) {
    aarr[arr[i]] = i;
  }
  memset(right0, 0, sizeof(right0));
  xx = sam.end;
  while (xx != 0) {
    right0[xx] = 1;
    xx = sam.f[xx];
  }
  for (i = sam.tail - 1; i >= 0; i--) {
    xx = arr[i];
    for (j = 0; j < 26; j++) {
      if (sam.next[xx][j] != -1) {
        right0[xx] += right0[sam.next[xx][j]];
      }
    }
  }
  scanf("%d", &n);
  memset(mark, 0, sizeof(mark));
  memset(inq, 0, sizeof(inq));
  for (i = 1; i <= n; i++) {
    scanf("%s", d);
    len2 = strlen(d);
    ans = 0;
    gao(i);
    printf("%I64d\n", ans);
  }
  return 0;
}
