Problem: Some days ago, WJMZBMR learned how to answer the query "how many times does a string x occur in a string s" quickly by preprocessing the string s. But now he wants to make it harder.

So he wants to ask "how many consecutive substrings of s are cyclical isomorphic to a given string x". You are given string s and n strings xi, for each string xi find, how many consecutive substrings of s are cyclical isomorphic to xi.

Two strings are called cyclical isomorphic if one can rotate one string to get the other one. 'Rotate' here means 'to take some consecutive chars (maybe none) from the beginning of a string and put them back at the end of the string in the same order'. For example, string "abcde" can be rotated to string "deabc". We can take characters "abc" from the beginning and put them at the end of "de".

Input

The first line contains a non-empty string s. The length of string s is not greater than 106 characters.

The second line contains an integer n (1 ≤ n ≤ 105) — the number of queries. Then n lines follow: the i-th line contains the string xi — the string for the i-th query. The total length of xi is less than or equal to 106 characters.

In this problem, strings only consist of lowercase English letters.

Output

For each query xi print a single integer that shows how many consecutive substrings of s are cyclical isomorphic to xi. Print the answers to the queries in the order they are given in the input.

Examples

Input

baabaabaaa
5
a
ba
baa
aabaa
aaba


Output

7
5
7
3
5


Input

aabbaa
3
aa
aabb
abba


Output

2
3
3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long double esp = 1e-11;
const long double PI = acos((long double)-1);
const long long int INF = 0x3f3f3f3fll;
const int MOD = 1000000007ll;
const int maxn = 1010100;
int pa[1010000 << 1], son[1010000 << 1][26], Right[1010000 << 1];
int Max[1010000 << 1], cnt, root, last;
inline int Newnode(int _Max) {
  ++cnt;
  memset(son[cnt], 0, sizeof(son[cnt]));
  Max[cnt] = _Max;
  return cnt;
}
inline void pre() {
  cnt = Max[0] = 0;
  root = last = Newnode(0);
}
inline void SAM(int alp) {
  int np = son[last][alp], u = last, v, nv;
  if (np && Max[np] == Max[last] + 1) {
    last = np;
    return;
  } else
    np = Newnode(Max[last] + 1);
  Right[np] = 1;
  while (u && !son[u][alp]) son[u][alp] = np, u = pa[u];
  if (!u)
    pa[np] = root;
  else {
    v = son[u][alp];
    if (Max[v] == Max[u] + 1)
      pa[np] = v;
    else {
      nv = Newnode(Max[u] + 1);
      Right[nv] = 0;
      memcpy(son[nv], son[v], sizeof(son[v]));
      pa[nv] = pa[v], pa[v] = pa[np] = nv;
      while (u && son[u][alp] == v) son[u][alp] = nv, u = pa[u];
    }
  }
  last = np;
}
int ttopo[1010000 << 1], topo[1010000 << 1], Min[1010000 << 1];
void topology() {
  int maxVal = 0;
  memset(ttopo, 0, sizeof(ttopo));
  for (int i = 1; i <= cnt; i++) maxVal = max(maxVal, Max[i]), ttopo[Max[i]]++;
  for (int i = 1; i <= maxVal; i++) ttopo[i] += ttopo[i - 1];
  for (int i = 1; i <= cnt; i++) topo[ttopo[Max[i]]--] = i;
  for (int i = cnt; i >= 1; i--)
    Right[pa[topo[i]]] += Right[topo[i]], Min[topo[i]] = Max[pa[topo[i]]] + 1;
  Min[1] = 0;
}
char s[maxn], ss[maxn * 2];
void test() {
  pre();
  int len = strlen(s);
  for (int x = 0; x < len; x++) SAM(s[x] - 'a');
  topology();
}
set<long long int> in;
long long int hashp = 751;
long long int hashval[maxn];
long long int hashpow[maxn];
void inithash(char* s, int len) {
  hashval[0] = s[0];
  for (int x = 1; x <= len - 1; x++)
    hashval[x] = (hashval[x - 1] * hashp + s[x]) % MOD;
  hashpow[0] = 1;
  for (int x = 1; x <= len - 1; x++) hashpow[x] = hashpow[x - 1] * hashp % MOD;
}
long long int seghash(int a, int b) {
  if (a == 0) return hashval[b];
  return ((hashval[b] - hashval[a - 1] * hashpow[b - a + 1]) % MOD + MOD) % MOD;
}
int main() {
  int q;
  scanf("%s%d", s, &q);
  test();
  for (int x = 1; x <= q; x++) {
    scanf("%s", ss);
    int t = root, l = 0;
    int len = strlen(ss);
    for (int x = len; x < len * 2 - 1; x++) ss[x] = ss[x - len];
    inithash(ss, len * 2 - 1);
    int las = -1;
    long long int ans = 0;
    in.clear();
    for (int o = len - 1; o <= 2 * len - 2; o++) {
      for (int x = las + 1; x <= o; x++) {
        while (t && son[t][ss[x] - 'a'] == 0) {
          t = pa[t];
          l = Max[t];
        }
        if (!t)
          t = root, l = 0;
        else
          t = son[t][ss[x] - 'a'], l++;
      }
      if (in.find(seghash(o - len + 1, o)) == in.end()) {
        in.insert(seghash(o - len + 1, o));
        if (l < len || t == root)
          ;
        else if (Min[t] <= len) {
          ans += Right[t];
        } else {
          int tp = pa[t];
          while (tp) {
            if (Min[tp] <= len && len <= Max[tp]) {
              ans += Right[tp];
              break;
            }
            tp = pa[tp];
          }
        }
      }
      las = o;
    }
    printf("%lld\n", ans);
  }
  return 0;
}