#include <bits/stdc++.h>
using namespace std;
const int A = 128;
const int N = (int)2e6 + 10;
const int V = 2 * N;
char str[N];
char query[N];
map<char, int> to[V], link[V];
int pi[N];
int parent[V];
int len[V], pos[V];
int countLeafs[V];
int suffLink[V];
int sz = 2;
int slen = 0;
int qlen = 0;
void attach(int a, int b, int p, int l) {
  to[a][str[p]] = b;
  pos[b] = p;
  len[b] = l;
  parent[b] = a;
}
void expand(char c) {
  int v, index = slen;
  for (v = sz - 1; !link[v].count(c); v = parent[v]) index -= len[v];
  int l = link[v][c];
  if (to[l].count(str[index])) {
    int u = to[l][str[index]];
    pos[sz] = pos[u];
    while (str[pos[sz]] == str[index]) {
      v = to[v][str[index]];
      pos[sz] += len[v];
      index += len[v];
    }
    int newLen = pos[sz] - pos[u];
    link[v][c] = sz;
    attach(l, sz, pos[u], newLen);
    attach(sz, u, pos[u] + newLen, len[u] - newLen);
    l = sz++;
  }
  attach(l, sz++, index, slen - index);
}
void initTree() {
  for (int i = 0; i < A; i++) link[0][i] = to[0][i] = 1;
  parent[1] = 0;
  len[1] = 1;
  pos[1] = 0;
}
void printTree(int v) {
  42;
  42;
  for (auto x : link[v]) 42;
  for (auto x : to[v]) 42;
  for (auto x : to[v]) printTree(x.second);
}
bool goChar(int &vertex, int &edgePosition, char c) {
  if (edgePosition < len[vertex]) {
    if (str[pos[vertex] + edgePosition] == c) {
      edgePosition++;
      return true;
    }
  } else {
    if (to[vertex].count(c)) {
      vertex = to[vertex][c];
      edgePosition = 1;
      return true;
    }
  }
  return false;
}
void goLink(int &vertex, int &edgePosition) {
  if (edgePosition == len[vertex]) {
    vertex = suffLink[vertex];
    edgePosition = len[vertex];
  } else {
    int p = parent[vertex];
    int startPosition = pos[vertex];
    int l = suffLink[p];
    int index = 0;
    while (index < edgePosition) {
      l = to[l][str[startPosition + index]];
      index += len[l];
    }
    vertex = l;
    edgePosition = len[vertex] - (index - edgePosition);
  }
}
void processQuery() {
  int answer = 0;
  int vertex = 1, edgePosition = 1;
  int it = 0;
  for (int i = 1; i < 2 * qlen; i++) {
    int p = pi[i - 1];
    while (p > 0 && query[i] != query[p]) p = pi[p - 1];
    if (query[i] == query[p]) p++;
    pi[i] = p;
  }
  for (int i = 0; i < qlen; i++) {
    while (it - i < qlen && goChar(vertex, edgePosition, query[it])) {
      it++;
    }
    if (pi[i + qlen - 1] >= qlen) break;
    if (it - i == qlen) answer += countLeafs[vertex];
    goLink(vertex, edgePosition);
  }
  printf("%d\n", answer);
}
void calcInfo(int v) {
  if (pos[v] + len[v] == slen) countLeafs[v] = 1;
  for (auto edge : to[v]) {
    int child = edge.second;
    calcInfo(child);
    countLeafs[v] += countLeafs[child];
  }
  for (auto l : link[v]) suffLink[l.second] = v;
}
int main() {
  scanf("%s", str);
  slen = strlen(str);
  str[slen++] = '$';
  initTree();
  for (int i = slen - 1; i >= 0; i--) {
    expand(str[i]);
  }
  suffLink[1] = 0;
  calcInfo(1);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf(" %s", query);
    qlen = strlen(query);
    strcat(query, query);
    processQuery();
  }
  return 0;
}
