#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << '(' << p.first << "," << p.second << ')';
}
const int LEN = 2000005;
struct SA {
  struct state {
    int len, link;
    map<char, int> next;
  };
  state st[LEN];
  int sz, last;
  long long cnt[LEN];
  bitset<LEN> vis;
  void SA_make() {
    sz = 0;
    st[0].len = 0, st[0].link = -1;
    ++sz;
    last = 0;
  }
  SA() { SA_make(); }
  void add(char c) {
    int new_n = sz++;
    st[new_n].len = st[last].len + 1;
    int pt = last;
    while (pt != -1 && !st[pt].next.count(c)) {
      st[pt].next[c] = new_n;
      pt = st[pt].link;
    }
    if (pt == -1) {
      st[new_n].link = 0;
    } else {
      int q_st = st[pt].next[c];
      if (st[q_st].len == st[pt].len + 1)
        st[new_n].link = q_st;
      else {
        int clone = sz++;
        st[clone] = st[q_st];
        st[clone].len = st[pt].len + 1;
        st[q_st].link = st[new_n].link = clone;
        while (pt != -1 && st[pt].next[c] == q_st) {
          st[pt].next[c] = clone;
          pt = st[pt].link;
        }
      }
    }
    last = new_n;
  }
  void count() {
    vector<int> v;
    for (int i = 1; i < sz; ++i) v.push_back(i);
    sort(v.begin(), v.end(),
         [&](int x, int y) { return st[x].len > st[y].len; });
    for (int i = 0; i < sz - 1; ++i) {
      cnt[st[v[i]].link] += cnt[v[i]];
    }
  }
  int minlen(int u) {
    if (u == 0) return 0;
    return st[st[u].link].len + 1;
  }
  void build(string &s) {
    for (char c : s) {
      add(c);
      ++cnt[last];
    }
    count();
  }
  long long query(string &t, int len) {
    vector<int> del;
    long long ans = 0;
    int cur_state = 0;
    int l = 0, r = -1;
    while (l < len && r < (long long)t.size()) {
      if (r - l + 1 == len) {
        if (!vis[cur_state])
          ans += cnt[cur_state], vis[cur_state] = 1, del.push_back(cur_state);
        int u = minlen(cur_state);
        if (u == len) {
          cur_state = st[cur_state].link;
        }
        ++l;
      } else {
        if (st[cur_state].next.count(t[r + 1]))
          cur_state = st[cur_state].next[t[r + 1]], ++r;
        else {
          int u = minlen(cur_state);
          if (u == r - l + 1) cur_state = st[cur_state].link;
          ++l;
          if (r < l - 1) ++r;
        }
      }
    }
    for (auto j : del) vis[j] = 0;
    return ans;
  }
  void go(string t = "aabb") {
    int cur = 0;
    cout << st[0].next['a'];
    for (int i = 0; i < 4; ++i) {
      if (st[cur].next.count(t[i])) {
        cur = st[cur].next[t[i]];
        cout << cur << "\n";
      }
    }
  }
} sa;
int _runtimeTerror_() {
  string s;
  cin >> s;
  sa.build(s);
  int n = (long long)s.size();
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    string t;
    cin >> t;
    t += t;
    t.pop_back();
    cout << sa.query(t, ((long long)t.size() + 1) / 2) << "\n";
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) _runtimeTerror_();
  return 0;
}
