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>
int N, Q, M;
char s[1000002], t[1000002];
struct SAM {
  int next[2000002][26], fail[2000002], len[2000002], n, last;
  SAM() { n = last = 1; }
  void push_back(int c) {
    int np = ++n, p = last;
    len[np] = len[p] + 1;
    while (p != 0 && next[p][c] == 0) {
      next[p][c] = np;
      p = fail[p];
    }
    if (p == 0)
      fail[np] = 1;
    else {
      int q = next[p][c];
      if (len[p] + 1 == len[q])
        fail[np] = q;
      else {
        int q2 = ++n;
        std::copy(next[q], next[q] + 26, next[q2]);
        fail[q2] = fail[q];
        fail[q] = fail[np] = q2;
        len[q2] = len[p] + 1;
        while (p != 0 && next[p][c] == q) {
          next[p][c] = q2;
          p = fail[p];
        }
      }
    }
    last = np;
  }
} sam;
int v[2000002];
std::vector<int> E[2000002];
int q[2000002], vi[2000002];
void BFS() {
  for (int i = 2; i <= sam.n; i++) E[sam.fail[i]].push_back(i);
  int H = 0, T = 1;
  q[1] = 1;
  while (H < T) {
    int u = q[++H];
    for (int e : E[u]) q[++T] = e;
  }
  for (int i = T; i > 1; i--) v[sam.fail[q[i]]] += v[q[i]];
}
int main() {
  scanf("%s", s + 1);
  while (s[N + 1]) N++;
  for (int i = 1; i <= N; i++) sam.push_back(s[i] - 'a');
  for (int i = 1, p = 1; i <= N; i++) v[p = sam.next[p][s[i] - 'a']]++;
  BFS();
  for (scanf("%d", &Q); Q; Q--) {
    scanf("%s", t + 1);
    M = 0;
    while (t[M + 1]) M++;
    int p = 1, nowlen = 0;
    long long O = 0;
    for (int i = 1; i <= M; i++) {
      while (p != 1 && sam.next[p][t[i] - 'a'] == 0)
        nowlen = sam.len[p = sam.fail[p]];
      if (sam.next[p][t[i] - 'a']) {
        p = sam.next[p][t[i] - 'a'];
        nowlen++;
      }
    }
    if (nowlen == M) {
      O += v[p];
      vi[p] = Q;
    }
    for (int i = 1; i <= M; i++) {
      while (p != 1 && sam.next[p][t[i] - 'a'] == 0)
        nowlen = sam.len[p = sam.fail[p]];
      if (sam.next[p][t[i] - 'a']) {
        p = sam.next[p][t[i] - 'a'];
        nowlen++;
      }
      while (sam.len[sam.fail[p]] >= M) nowlen = sam.len[p = sam.fail[p]];
      if (nowlen >= M) {
        if (vi[p] == Q) break;
        O += v[p];
        vi[p] = Q;
      }
    }
    printf("%lld\n", O);
  }
}