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>
template <typename Tp>
Tp Max(const Tp &a, const Tp &b) {
  return a > b ? a : b;
}
template <typename Tp>
Tp Min(const Tp &a, const Tp &b) {
  return a < b ? a : b;
}
template <typename Tp>
void Read(Tp &x) {
  Tp in = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    in = in * 10 + ch - '0';
    ch = getchar();
  }
  x = in * f;
}
const int SN = 2000000 + 10;
int ch[SN][26], len[SN], fail[SN], TIME, last, S, n, N, M;
int d[SN], right[SN], vis[SN], sta[SN], top;
char s[SN];
void Insert(int x) {
  int now = ++TIME, p = last, to = s[x] - 'a';
  last = now, len[now] = len[p] + 1;
  for (; p && !ch[p][to]; p = fail[p]) ch[p][to] = now;
  if (!p)
    fail[now] = S;
  else {
    int q = ch[p][to];
    if (len[q] == len[p] + 1) {
      fail[now] = q;
      return;
    }
    int Nq = ++TIME;
    memcpy(ch[Nq], ch[q], sizeof ch[q]);
    fail[Nq] = fail[q], len[Nq] = len[p] + 1;
    fail[q] = fail[now] = Nq;
    for (; p && ch[p][to] == q; p = fail[p]) ch[p][to] = Nq;
  }
}
int main() {
  last = S = TIME = 1;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) Insert(i);
  for (int i = 1; i <= TIME; i++) d[fail[i]]++;
  for (int now = S, i = 1; i <= n; i++) now = ch[now][s[i] - 'a'], right[now]++;
  for (int i = 1; i <= TIME; i++)
    if (!d[i]) sta[++top] = i;
  while (top) {
    int now = sta[top--];
    right[fail[now]] += right[now];
    if (!(--d[fail[now]])) sta[++top] = fail[now];
  }
  Read(N);
  while (N--) {
    scanf("%s", s + 1);
    M = strlen(s + 1);
    n = M;
    for (int i = 1; i < M; i++) s[++n] = s[i];
    int now = S, max = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      int to = s[i] - 'a';
      if (ch[now][to])
        now = ch[now][to], max++;
      else {
        while (now && !ch[now][to]) now = fail[now];
        if (!now)
          now = S, max = 0;
        else if (ch[now][to])
          max = len[now] + 1, now = ch[now][to];
      }
      if (max == M) {
        if (vis[now] != N + 1) ans += right[now], vis[now] = N + 1;
        max--;
        if (max <= len[fail[now]]) now = fail[now];
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}