#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6;
struct SuffixAutomaton {
  int len[2 * MX];
  int link[2 * MX];
  map<int, int> to[2 * MX];
  bool terminal[2 * MX];
  int last;
  int sz;
  bool vis[2 * MX];
  SuffixAutomaton() {
    last = 0;
    sz = 1;
    link[0] = -1;
    len[0] = 0;
  }
  void addLetter(char c) {
    int p = last;
    last = sz++;
    len[last] = len[p] + 1;
    while (p != -1 && to[p][c] == 0) {
      to[p][c] = last;
      p = link[p];
    }
    if (p == -1) {
      link[last] = 0;
      return;
    }
    int q = to[p][c];
    if (len[q] == len[p] + 1) {
      link[last] = q;
      return;
    }
    int clone = sz++;
    to[clone] = to[q];
    link[clone] = link[q];
    link[last] = link[q] = clone;
    len[clone] = len[p] + 1;
    while (p != -1 && to[p][c] == q) {
      to[p][c] = clone;
      p = link[p];
    }
  }
  void markTerminal() {
    int u = last;
    while (u != 0) {
      terminal[u] = true;
      u = link[u];
    }
  }
  void build(string &s) {
    for (char c : s) addLetter(c);
    markTerminal();
  }
  int dp[2 * MX];
  bool used[2 * MX];
  int countPath(int u) {
    if (used[u]) {
      return dp[u];
    }
    used[u] = true;
    dp[u] = terminal[u];
    for (auto transition : to[u]) {
      int v = transition.second;
      assert(v != 0);
      dp[u] += countPath(v);
    }
    return dp[u];
  }
  long long countCyclic(string &t) {
    int node = 0;
    long long ans = 0;
    int curLen = 0;
    int sz = t.size();
    t += t;
    vector<int> nodes;
    for (int i = 0; i < t.size(); i++) {
      while (node > 0 && to[node].find(t[i]) == to[node].end()) {
        node = link[node];
        curLen = len[node];
      }
      if (to[node].find(t[i]) != to[node].end()) {
        node = to[node][t[i]];
        curLen++;
      } else {
        curLen = 0;
      }
      while (curLen >= sz && len[link[node]] >= sz) {
        node = link[node];
        curLen = len[node];
      }
      if (i >= sz && curLen >= sz && !vis[node]) {
        ans += countPath(node);
        vis[node] = true;
        nodes.push_back(node);
      }
    }
    for (int u : nodes) {
      vis[u] = false;
    }
    return ans;
  }
} automaton;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  automaton.build(s);
  long long Q;
  cin >> Q;
  for (long long i = 0; i < (long long)Q; i++) {
    string p;
    cin >> p;
    cout << automaton.countCyclic(p) << "\n";
  }
  return 0;
}
