#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umax(T &x, T y) {
  return (x < y) ? x = y, true : false;
}
template <class T>
bool umin(T &x, T y) {
  return (x > y) ? x = y, true : false;
}
struct SAM {
  struct state {
    int fa, len;
    vector<int> nxt;
  };
  vector<state> m;
  vector<int> R, idx;
  void init() {
    m.assign(2, {0, 0, vector<int>(26)});
    R.assign(2, 0);
  }
  int add() {
    m.resize(m.size() + 1);
    R.push_back(0);
    return m.size() - 1;
  }
  int touch(int x, int c) {
    int y = m[x].nxt[c], len = m[x].len + 1;
    if (y) {
      if (m[y].len == len) return y;
      int z = add();
      m[z] = {m[y].fa, len, m[y].nxt};
      for (m[y].fa = z; m[x].nxt[c] == y; x = m[x].fa) m[x].nxt[c] = z;
      return z;
    } else {
      y = add();
      for (; x && !m[x].nxt[c]; x = m[x].fa) m[x].nxt[c] = y;
      int fa = (!x) ? 1 : touch(x, c);
      m[y] = {fa, len, m[0].nxt};
      return y;
    }
  }
  int extend(int x, int c) {
    int res = touch(x, c);
    return R[res]++, res;
  }
  void prepare() {
    idx.assign(m.size(), 0);
    vector<int> cnt(m.size());
    for (int i = 0; i < (m.size()); i++) cnt[m[i].len]++;
    for (int i = (1); i < (m.size()); i++) cnt[i] += cnt[i - 1];
    for (int i = (m.size()) - 1; i >= 0; i--) idx[--cnt[m[i].len]] = i;
    for (int i = (m.size()) - 1; i >= (2); i--) R[m[idx[i]].fa] += R[idx[i]];
  }
  long long solve(string &s) {
    int x = 1, len = 0;
    int pos = 0;
    for (auto c : s) {
      c -= 'a';
      while (x && !m[x].nxt[c]) x = m[x].fa, len = m[x].len;
      if (!x)
        x = 1, len = 0;
      else
        x = m[x].nxt[c], ++len;
    }
    int sx = -1;
    long long res = 0;
    for (auto c : s) {
      c -= 'a';
      while (x && !m[x].nxt[c]) x = m[x].fa, len = m[x].len;
      if (!x)
        x = 1, len = 0;
      else
        x = m[x].nxt[c], ++len;
      for (;;) {
        int y = m[x].fa;
        if (m[y].len < ((int)(s).length())) break;
        x = y;
        len = m[y].len;
      }
      if (len >= ((int)(s).length())) {
        if (x == sx) break;
        if (sx == -1) sx = x;
        res += R[x];
      }
    }
    return res;
  }
} sam;
void prepare() {}
void input() {
  string s;
  cin >> s;
  int last = 1;
  sam.init();
  for (auto c : s) last = sam.extend(last, c - 'a');
  sam.prepare();
}
void solve() {
  int q;
  for (cin >> q; q--;) {
    string t;
    cin >> t;
    cout << sam.solve(t) << endl;
  }
}
void output() {}
int main() {
  prepare();
  input();
  solve();
  output();
  return 0;
}
