#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct SAM {
  struct State {
    int to[26];
    int fa, len;
  };
  vector<State> t;
  int lst;
  void inline init() {
    t.clear();
    t.push_back(State());
    t.push_back(State());
    lst = 1;
    t[1].fa = t[1].len = 0;
  }
  SAM() { init(); }
  int inline size() { return ((int)(t).size()) - 1; }
  State inline &operator[](int x) { return t[x]; }
  int inline newnode() {
    t.push_back(State());
    return ((int)(t).size()) - 1;
  }
  int inline add(int p, int c) {
    int np = newnode();
    t[np].len = t[p].len + 1;
    while (p && !t[p].to[c]) {
      t[p].to[c] = np;
      p = t[p].fa;
    }
    if (!p) {
      t[np].fa = 1;
    } else {
      int q = t[p].to[c];
      if (t[p].len + 1 == t[q].len) {
        t[np].fa = q;
      } else {
        int nq = newnode();
        t[nq] = t[q];
        t[nq].len = t[p].len + 1;
        t[q].fa = t[np].fa = nq;
        while (p && t[p].to[c] == q) {
          t[p].to[c] = nq;
          p = t[p].fa;
        }
      }
    }
    return lst = np;
  }
  int inline add(int c) { return add(lst, c); }
} sam;
char s[1 << 20];
int n, m, k, p;
char t[1 << 17];
vector<int> nei[1 << 21];
int cn[1 << 21];
int ep[1 << 21];
void inline dfs(int now) {
  for (int i = 0; i < (((int)(nei[now]).size())); ++i) {
    int to = nei[now][i];
    dfs(to);
    cn[now] += cn[to];
    ep[now] = ep[to];
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  sam.init();
  for (int i = 1; i <= (n); ++i) {
    int pos = sam.add(s[i] - 'a');
    cn[pos] = 1;
    ep[pos] = i;
  }
  p = ((int)(sam).size());
  for (int i = 1; i <= (p); ++i) nei[sam[i].fa].push_back(i);
  dfs(1);
  scanf("%d", &m);
  while (m--) {
    scanf("%s", t);
    int now = 1;
    k = strlen(t);
    int len = 0;
    for (int i = 0; i < (k); ++i) {
      while (now && !sam[now].to[t[i] - 'a'])
        now = sam[now].fa, len = sam[now].len;
      if (!now)
        now = 1, len = 0;
      else
        now = sam[now].to[t[i] - 'a'], ++len;
    }
    set<int> lgl;
    long long ans = 0;
    for (int i = 0; i < (k); ++i) {
      if (i) {
        if (sam[sam[now].fa].len == k - 1) {
          now = sam[now].fa;
        }
        len = min(len, k - 1);
        while (now && !sam[now].to[t[i - 1] - 'a'])
          now = sam[now].fa, len = sam[now].len;
        if (!now)
          now = 1, len = 0;
        else
          now = sam[now].to[t[i - 1] - 'a'], ++len;
      }
      if (len == k) {
        if (lgl.count(now)) continue;
        lgl.insert(now);
        ans += cn[now];
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
