#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 21;
const int maxn = 2e6 + 10;
const int maxm = 1e5 + 10;
const int base = 29;
const int mod = 1e9 + 7;
const int base2 = 31;
const int mod2 = 1e9 + 9;
const int INF = 2e18 + 100;
const int SQ = 317;
int last;
int sz = 1;
int len[maxn];
int link[maxn];
int nxt[maxn][26];
inline void addLetter(int c) {
  int p = last;
  last = sz++;
  len[last] = len[p] + 1;
  for (; p != -1 && nxt[p][c] == 0; p = link[p]) {
    nxt[p][c] = last;
  }
  if (p == -1) {
    link[last] = 0;
    return;
  }
  int q = nxt[p][c];
  if (len[q] == len[p] + 1) {
    link[last] = q;
    return;
  }
  int cl = sz++;
  for (int j = 0; j < 26; j++) nxt[cl][j] = nxt[q][j];
  link[cl] = link[q];
  len[cl] = len[p] + 1;
  link[q] = link[last] = cl;
  for (; nxt[p][c] == q; p = link[p]) nxt[p][c] = cl;
}
int cnt[maxn];
bool mark[maxn];
inline void calc(int state) {
  if (mark[state]) return;
  mark[state] = true;
  for (int i = 0; i < 26; i++) {
    if (nxt[state][i]) {
      calc(nxt[state][i]);
      cnt[state] += cnt[nxt[state][i]];
    }
  }
}
int kmp[maxn];
inline int repeat(string &t) {
  int tmp = 0;
  for (int i = 1; i < t.size(); i++) {
    while (tmp && t[tmp] != t[i]) tmp = kmp[tmp - 1];
    if (t[tmp] == t[i]) tmp++;
    kmp[i] = tmp;
  }
  int v = (int)t.size() - kmp[(int)t.size() - 1];
  if ((int)t.size() % v == 0) return v;
  return (int)t.size();
}
inline int Count(string &t) {
  int ret = 0;
  int state = 0, ln = 0;
  int lim = repeat(t);
  for (int i = 0; i < (int)t.size() + lim - 1; i++) {
    int cur = i % ((int)t.size());
    while (state != -1 && nxt[state][t[cur] - 'a'] == 0) {
      state = link[state];
      if (state != -1) ln = len[state];
    }
    if (state == -1)
      state = ln = 0;
    else
      state = nxt[state][t[cur] - 'a'], ln++;
    if (ln == t.size()) {
      ret += cnt[state];
      ln--;
      while (link[state] != -1 && len[link[state]] >= ln) state = link[state];
    }
  }
  return ret;
}
int32_t main() {
  link[0] = -1;
  string s = get();
  for (int i = 0; i < s.size(); i++) addLetter(s[i] - 'a');
  for (int p = last; p != -1; p = link[p]) cnt[p]++;
  calc(0);
  int n = in();
  for (int i = 0; i < n; i++) {
    string t = get();
    printf("%d\n", Count(t));
  }
}
