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;
vector<int> V;
struct r_e_d {
  inline int gti() {
    int x = 0, w = 1;
    char ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9')
      x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    return x * w;
  }
  inline long long gtl() {
    long long x = 0, w = 1;
    char ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9')
      x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    return x * w;
  }
  inline string gts() {
    string S;
    char ch = getchar();
    while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar();
    while (ch != ' ' && ch != '\n' && ch != '\r')
      S.push_back(ch), ch = getchar();
    return S;
  }
} RD;
struct suffix_auto_machine {
  int ch[2000005][26], fa[2000005], mx[2000005], tu[2000005], bn[2000005],
      sz[2000005], tt, la, bj[2000005];
  void push(int x) {
    int np = ++tt, p = la;
    la = np;
    mx[np] = mx[p] + 1;
    for (; p && !ch[p][x]; p = fa[p]) ch[p][x] = np;
    if (!p)
      fa[np] = 1;
    else {
      int q = ch[p][x];
      if (mx[q] == mx[p] + 1)
        fa[np] = q;
      else {
        int nq = ++tt;
        mx[nq] = mx[p] + 1;
        memcpy(ch[nq], ch[q], sizeof(ch[q]));
        fa[nq] = fa[q];
        fa[q] = fa[np] = nq;
        for (; p && ch[p][x] == q; p = fa[p]) ch[p][x] = nq;
      }
    }
    sz[np] = 1;
  }
  void build(string S) {
    tt = la = 1;
    for (int i = (0); i < (S.size()); ++i) push(S[i] - 'a');
    for (int i = (1); i <= (tt); ++i) ++bn[mx[i]];
    for (int i = (1); i <= (tt); ++i) bn[i] += bn[i - 1];
    for (int i = (1); i <= (tt); ++i) tu[bn[mx[i]]--] = i;
    for (int i = (tt); i >= (1); --i) sz[fa[tu[i]]] += sz[tu[i]];
  }
  void find(string S) {
    S = S + S;
    long long as = 0;
    int nw = 1, le = 0;
    for (int i = (0); i < (((int)S.size() - 1)); ++i) {
      for (; nw && ch[nw][S[i] - 'a'] == 0; nw = fa[nw])
        ;
      if (nw == 0) nw = 1;
      le = min(le, mx[nw]);
      ++le;
      nw = ch[nw][S[i] - 'a'];
      le = min(le, mx[nw]);
      for (; nw && min(le, mx[fa[nw]]) >= (S.size() >> 1); nw = fa[nw])
        le = min(le, mx[fa[nw]]);
      if (le >= S.size() / 2 && bj[nw] == 0)
        as += sz[nw], bj[nw] = 1, V.push_back(nw);
    }
    printf("%lld\n", as);
    while (V.size()) bj[V.back()] = 0, V.pop_back();
  }
} SAM;
string S;
int n;
int main() {
  S = RD.gts();
  SAM.build(S);
  n = RD.gti();
  for (int i = (1); i <= (n); ++i) {
    S = RD.gts();
    SAM.find(S);
  }
  return 0;
}