#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
void tr() { cout << endl; }
template <typename S, typename... Strings>
void tr(S x, const Strings&... rest) {
  cout << x << ' ';
  tr(rest...);
}
const int N = 1001000;
const int M = 26;
struct suffixAutomaton {
  struct state {
    int len, link;
    int next[M];
    long long cnt;
    bool terminal;
    state() {
      len = 0, link = -1, cnt = 0;
      terminal = false;
      for (int i = 0; i < M; i++) next[i] = -1;
    }
  };
  state st[N * 2];
  int sz, last;
  char offset = 'a';
  suffixAutomaton(string& s) {
    int l = s.length();
    for (int i = 0; i < 2 * l; i++) st[i] = state();
    sz = 1, last = 0;
    st[0].len = 0;
    st[0].link = -1;
    for (int i = 0; i < l; i++) addChar(s[i] - offset);
    for (int i = last; i != -1; i = st[i].link) st[i].terminal = true;
  }
  void addChar(int c) {
    int cur = sz++;
    assert(cur < N * 2);
    st[cur].len = st[last].len + 1;
    st[cur].cnt = 1;
    int p = last;
    while (p != -1 and st[p].next[c] == -1) {
      st[p].next[c] = cur;
      p = st[p].link;
    }
    last = cur;
    if (p == -1) {
      st[cur].link = 0;
      return;
    }
    int q = st[p].next[c];
    if (st[q].len == st[p].len + 1) {
      st[cur].link = q;
      return;
    }
    int clone = sz++;
    for (int i = 0; i < M; i++) st[clone].next[i] = st[q].next[i];
    st[clone].link = st[q].link;
    st[clone].len = st[p].len + 1;
    st[clone].cnt = 0;
    while (p != -1 and st[p].next[c] == q) {
      st[p].next[c] = clone;
      p = st[p].link;
    }
    st[q].link = st[cur].link = clone;
    return;
  }
  bool contains(string& t) {
    int cur = 0;
    for (int i = 0; i < t.length(); i++) {
      cur = st[cur].next[t[i] - offset];
      if (cur == -1) return false;
    }
    return true;
  }
  long long numberOfSubstrings() {
    long long res = 0;
    for (int i = 1; i < sz; i++) res += st[i].len - st[st[i].link].len;
    return res;
  }
  long long h[2 * N];
  long long base = 29;
  long long pr = 1e9 + 7;
  set<long long> done;
  long long p[2 * N];
  void numberOfOccPreprocess() {
    vector<pair<int, int> > v;
    for (int i = 1; i < sz; i++) v.push_back(make_pair(st[i].len, i));
    sort(v.begin(), v.end(), greater<pair<int, int> >());
    for (int i = 0; i < sz - 1; i++) {
      int suf = st[v[i].second].link;
      st[suf].cnt += st[v[i].second].cnt;
    }
    p[0] = 1;
    for (int i = 1; i < 2 * N; i++) {
      p[i] = (p[i - 1] * base) % pr;
    }
  }
  long long numberOfOcc(string& t) {
    long long res = 0;
    int cur = 0;
    int l = 0, m = t.length();
    done.clear();
    string tmp = t + t;
    h[0] = 0;
    for (int i = 1; i <= 2 * m; i++) {
      h[i] = ((h[i - 1] * base) + (tmp[i - 1] - offset + 1)) % pr;
    }
    for (int i = 0; i < m; i++) {
      while (cur != 0 and st[cur].next[t[i] - offset] == -1) {
        cur = st[cur].link;
        l = st[cur].len;
      }
      int nxt = st[cur].next[t[i] - offset];
      if (nxt == -1)
        nxt = 0, l = 0;
      else
        l++;
      cur = nxt;
    }
    if (l == m) {
      res += st[cur].cnt;
      done.insert(h[m]);
    }
    for (int i = 0; i < m - 1; i++) {
      while (cur != 0 and st[cur].next[t[i] - offset] == -1) {
        cur = st[cur].link;
        l = st[cur].len;
      }
      int nxt = st[cur].next[t[i] - offset];
      if (nxt == -1)
        nxt = 0, l = 0;
      else
        l++;
      cur = nxt;
      if (l > m) {
        if (l - 1 == st[st[cur].link].len) cur = st[cur].link;
        l--;
      }
      long long v1 = h[m + i + 1];
      long long v2 = (h[i + 1] * p[m]) % pr;
      v1 = (v1 - v2 + pr) % pr;
      if (l == m and !done.count(v1)) {
        res += st[cur].cnt;
        done.insert(v1);
      }
    }
    return res;
  }
};
string s;
string t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  suffixAutomaton* suf = new suffixAutomaton(s);
  suf->numberOfOccPreprocess();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    cout << suf->numberOfOcc(t) << '\n';
  }
  return 0;
}
