#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
struct Node {
  vi to;
  int mxln;
  int lk;
  Node() : to(27, -1), mxln(0), lk(-1) {}
  Node(int mxln) : to(27, -1), mxln(mxln), lk(-1) {}
  Node(const vi& to, int mxln, int lk) : to(to), mxln(mxln), lk(lk) {}
};
vector<Node> au(1);
int lst;
void append(char ch) {
  ch -= 'a';
  int cur = (int)((au).size());
  au.emplace_back(au[lst].mxln + 1);
  int pv = lst;
  for (; pv != -1 && au[pv].to[ch] == -1; pv = au[pv].lk) {
    au[pv].to[ch] = cur;
  }
  if (pv == -1) {
    au[cur].lk = 0;
  } else {
    int nxt = au[pv].to[ch];
    if (au[nxt].mxln == au[pv].mxln + 1) {
      au[cur].lk = nxt;
    } else {
      int cl = (int)((au).size());
      au.emplace_back(au[nxt].to, au[pv].mxln + 1, au[nxt].lk);
      au[cur].lk = au[nxt].lk = cl;
      for (; pv != -1 && au[pv].to[ch] == nxt; pv = au[pv].lk) {
        au[pv].to[ch] = cl;
      }
    }
  }
  lst = cur;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  s.insert(s.begin(), 'z' + 1);
  int n = (int)((s).size());
  for (auto ch : s) {
    append(ch);
  }
  vector<pii> ord((int)((au).size()));
  for (int i = 0; i < (int)((au).size()); i++) {
    ord[i] = make_pair(au[i].mxln, i);
  }
  sort((ord).begin(), (ord).end());
  reverse((ord).begin(), (ord).end());
  ord.pop_back();
  vi lfs((int)((au).size()));
  for (auto v : ord) {
    if (!lfs[v.second]) lfs[v.second] = 1;
    lfs[au[v.second].lk] += lfs[v.second];
  }
  int q;
  cin >> q;
  vi lt((int)((au).size()));
  int ct = 0;
  while (q--) {
    string t;
    cin >> t;
    int len = (int)((t).size());
    t += t;
    ct++;
    int ans = 0;
    int v = 0;
    for (int i = 0, r = -1; i < len; i++) {
      while (r - i + 1 < len && au[v].to[t[r + 1] - 'a'] != -1) {
        r++;
        v = au[v].to[t[r] - 'a'];
      }
      if (r - i + 1 == len) {
        if (lt[v] != ct) {
          ans += lfs[v];
          lt[v] = ct;
        }
      }
      if (au[au[v].lk].mxln == r - i) {
        v = au[v].lk;
      }
    }
    cout << ans << '\n';
  }
}
