#include <bits/stdc++.h>
using namespace std;
struct State {
  int len, link;
  map<char, int> nxtc;
} SA[2 * 2000006];
vector<pair<int, int> > lenState;
int FirstPos[2 * 2000006], NumOcc[2 * 2000006];
class SuffixAutomata {
  int sz, last, lm;
  int fnl;
  void init(int idx) {
    SA[idx].len = 0, SA[idx].link = -1;
    FirstPos[idx] = -1;
    SA[idx].nxtc.clear();
  }

 public:
  SuffixAutomata() {
    sz = last = 0;
    init(0);
    lenState.clear();
    lm = 0;
    ++sz;
  }
  int size() { return sz; }
  void extend(char ch, int idx = -1) {
    int p, q, clone, cur = sz++;
    lm = fnl = cur;
    init(cur);
    SA[cur].len = SA[last].len + 1;
    FirstPos[cur] = idx;
    lenState.push_back(make_pair(SA[cur].len, cur));
    for (p = last; p != -1 && SA[p].nxtc.count(ch) == 0; p = SA[p].link)
      SA[p].nxtc[ch] = cur;
    if (p == -1)
      SA[cur].link = 0;
    else {
      q = SA[p].nxtc[ch];
      if (SA[p].len + 1 == SA[q].len)
        SA[cur].link = q;
      else {
        clone = sz++;
        init(clone);
        SA[clone] = SA[q];
        SA[clone].len = SA[p].len + 1;
        for (; p != -1 && SA[p].nxtc[ch] == q; p = SA[p].link)
          SA[p].nxtc[ch] = clone;
        SA[cur].link = SA[q].link = clone;
        FirstPos[clone] = FirstPos[q];
        lenState.push_back(make_pair(SA[clone].len, clone));
      }
    }
    last = cur;
  }
  void numOcc() {
    int i, p, q;
    map<char, int>::iterator im;
    memset(NumOcc, 0, sizeof(NumOcc));
    NumOcc[lm] = 1;
    sort(lenState.begin(), lenState.end());
    for (i = lenState.size() - 1; i >= 0; --i) {
      p = lenState[i].second;
      if (p < 1) continue;
      map<char, int> &M = SA[p].nxtc;
      for (im = M.begin(); im != M.end(); ++im) {
        q = im->second;
        NumOcc[p] += NumOcc[q];
      }
    }
  }
  long long run(char *pat, int len) {
    int p, cur = 0, match = 0, link;
    char ch;
    long long ret = 0;
    for (p = 0; p + 1 < len; ++p) {
      ch = pat[p];
      while (cur && SA[cur].nxtc.count(ch) == 0)
        cur = SA[cur].link,
        match = ((match) < (SA[cur].len) ? (match) : (SA[cur].len));
      if (SA[cur].nxtc.count(ch)) cur = SA[cur].nxtc[ch], ++match;
      if (SA[cur].len < match) match = SA[cur].len;
    }
    for (; pat[p]; ++p) {
      ch = pat[p];
      while (cur && SA[cur].nxtc.count(ch) == 0)
        cur = SA[cur].link,
        match = ((match) < (SA[cur].len) ? (match) : (SA[cur].len));
      if (SA[cur].nxtc.count(ch)) cur = SA[cur].nxtc[ch], ++match;
      if (SA[cur].len < match) match = SA[cur].len;
      link = SA[cur].link;
      while (SA[cur].len > len && SA[link].len >= len)
        cur = link, match = ((match) < (SA[cur].len) ? (match) : (SA[cur].len));
      if (match >= len) ret += NumOcc[cur];
    }
    return ret;
  }
  void print() {
    int cur;
    for (cur = 0; cur < sz; ++cur)
      printf("%d : %d %d #%d\n", cur, SA[cur].len, SA[cur].link, NumOcc[cur]);
  }
};
char str[2000006], pat[2000006];
int failure[2000006];
int kmp(int len) {
  int i, f;
  f = failure[0] = -1;
  for (i = 1; pat[i]; ++i) {
    while (f != -1 && pat[f + 1] != pat[i]) f = failure[f];
    if (pat[f + 1] == pat[i]) ++f;
    failure[i] = f;
  }
  for (i = len; pat[i]; ++i) {
    if (failure[i] + 1 >= len) break;
  }
  return i;
}
long long processPat(SuffixAutomata &sa) {
  int len = strlen(pat), p;
  pat[2 * len - 1] = 0;
  for (p = 2 * len - 2; p >= len; --p) pat[p] = pat[p - len];
  pat[kmp(len)] = 0;
  return sa.run(pat, len);
}
int main() {
  int i, Q;
  while (scanf("%s", str) != EOF) {
    SuffixAutomata sa;
    for (i = 0; str[i]; ++i) sa.extend(str[i]);
    sa.extend('#');
    sa.numOcc();
    scanf("%d", &Q);
    while (Q--) {
      scanf("%s", pat);
      printf("%I64d\n", processPat(sa));
    }
    return 0;
  }
  return 0;
}
