#include <bits/stdc++.h>
using namespace std;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
}
const int inf = 1e9;
const int maxn = 4 * 1e6 + 5;
char s[maxn];
unordered_map<int, int> to[maxn];
int len[maxn], fipos[maxn], link[maxn];
int depth[maxn];
int node, pos;
int sz = 1, n = 0;
int remain = 0;
int make_node(int _pos, int _len) {
  fipos[sz] = _pos;
  len[sz] = _len;
  return sz++;
}
void go_edge(int &node, int &pos) {
  while (pos > len[to[node][s[n - pos]]]) {
    node = to[node][s[n - pos]];
    pos -= len[node];
  }
}
void add_letter(int c) {
  s[n++] = c;
  pos++;
  int last = 0;
  remain++;
  while (pos > 0) {
    go_edge(node, pos);
    int edge = s[n - pos];
    int &v = to[node][edge];
    int t = s[fipos[v] + pos - 1];
    if (v == 0) {
      remain--;
      v = make_node(n - pos, inf);
      link[last] = node;
      last = 0;
    } else if (t == c) {
      link[last] = node;
      return;
    } else {
      remain--;
      int u = make_node(fipos[v], pos - 1);
      to[u][c] = make_node(n - 1, inf);
      to[u][t] = v;
      fipos[v] += pos - 1;
      len[v] -= pos - 1;
      v = u;
      link[last] = u;
      last = u;
    }
    if (node == 0)
      pos--;
    else
      node = link[node];
  }
}
int val[maxn];
int slen;
void dfs(int u, int d = 0) {
  val[u] = (len[u] > slen + 2) && (u != 0);
  depth[u] = min(inf, d);
  for (auto it : to[u]) {
    int v = it.second;
    if (v) {
      dfs(v, d + len[v]);
      val[u] += val[v];
    }
  }
}
void fix(int &node, int &edg, int &pos, int &st, int &en, string &s) {
  int fichar = s[st + depth[node]];
  edg = to[node][fichar];
  while (edg && pos > len[edg]) {
    node = edg;
    pos -= len[edg];
    fichar = s[st + depth[node]];
    edg = to[node][fichar];
  }
}
int main(int argc, char *argv[]) {
  io();
  len[0] = inf;
  string s;
  cin >> s;
  slen = s.length();
  s += '$';
  for (auto c : s) {
    add_letter(c);
  }
  dfs(0);
  int q;
  cin >> q;
  string str;
  while (q--) {
    cin >> str;
    int l = str.length();
    if (l > slen) {
      cout << 0 << '\n';
      continue;
    }
    str = str + str;
    long long ans = 0;
    int st = 0;
    int en = 0;
    int node = 0;
    int edg = 0;
    int pos = 1;
    set<pair<int, pair<int, int>>> done;
    while (st < l) {
      fix(node, edg, pos, st, en, str);
      assert(st <= en);
      if (edg == 0) {
        if (node == 0) {
          pos--;
        } else {
          node = link[node];
        }
        st++;
        if (st > en) {
          en++;
        }
        continue;
      }
      while (en < (st + l)) {
        fix(node, edg, pos, st, en, str);
        int spos = fipos[edg] + pos - 1;
        if (spos >= slen) {
          break;
        }
        if (s[spos] == str[st + depth[node] + pos - 1]) {
          en++;
          pos++;
          fix(node, edg, pos, st, en, str);
        } else {
          break;
        }
      }
      if (en == st + l) {
        if (done.find({node, {edg, pos}}) == done.end()) {
          done.insert({node, {edg, pos}});
          if (pos == 1) {
            if (node != 0) ans = ans + val[node];
          } else {
            if (edg != 0) ans = ans + val[edg];
          }
        } else {
        }
      }
      st++;
      if (st > en) {
        en++;
      }
      if (node == 0)
        pos--;
      else
        node = link[node];
    }
    cout << ans << '\n';
  }
  return 0;
}
