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;
const int MAXM = 2e6 + 5;
struct SAM {
  int Go[26], fail, Len, Num;
} A[MAXM];
char S[MAXM], T[MAXM];
int tot, Q, Root, Len, LenT, Ord[MAXM], Flag[MAXM];
void BuildSAM() {
  int p;
  p = Root = tot = 1;
  Len = strlen(S + 1);
  for (int i = 1; i <= Len; i++) {
    int ch = S[i] - 'a';
    int np = ++tot;
    A[np].Len = A[p].Len + 1;
    A[np].Num = 1;
    for (; p && !A[p].Go[ch]; p = A[p].fail) A[p].Go[ch] = np;
    if (!p)
      A[np].fail = Root;
    else {
      int q = A[p].Go[ch];
      if (A[p].Len + 1 == A[q].Len)
        A[np].fail = q;
      else {
        int nq = ++tot;
        A[nq] = A[q];
        A[q].fail = A[np].fail = nq;
        A[nq].Len = A[p].Len + 1, A[nq].Num = 0;
        for (; p && A[p].Go[ch] == q; p = A[p].fail) A[p].Go[ch] = nq;
      }
    }
    p = np;
  }
}
bool Cmp(int x, int y) { return A[x].Len > A[y].Len; }
void GetRight() {
  for (int i = 1; i <= tot; i++) Ord[i] = i;
  sort(Ord + 1, Ord + tot + 1, Cmp);
  for (int i = 1; i <= tot; i++) {
    int Now = Ord[i];
    A[A[Now].fail].Num += A[Now].Num;
  }
}
void Solve(int time) {
  scanf("%s", T + 1);
  int LenT = strlen(T + 1);
  for (int i = 1; i <= LenT; i++) T[i + LenT] = T[i];
  int Now = Root, Ans = 0, len = 0;
  for (int i = 1; i <= 2 * LenT; i++) {
    int ch = T[i] - 'a';
    for (; Now && !A[Now].Go[ch]; Now = A[Now].fail)
      ;
    len = (!A[Now].Go[ch]) ? 0 : min(len, A[Now].Len) + 1;
    if (A[Now].Go[ch]) Now = A[Now].Go[ch];
    for (; A[A[Now].fail].Len >= LenT; Now = A[Now].fail, len = A[Now].Len)
      ;
    if (len >= LenT && Flag[Now] != time) Ans += A[Now].Num, Flag[Now] = time;
  }
  printf("%d\n", Ans);
}
int main() {
  scanf("%s", S + 1);
  BuildSAM();
  GetRight();
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) Solve(i);
}