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>
const int N = 1000010 << 1;
using namespace std;
struct SAM {
  int n, step[N], fa[N], ch[N][26], right[N], num[N], last, root, cnt;
  char s[N >> 1];
  SAM() { last = root = ++cnt; }
  void add(int x) {
    int pro = s[x] - 'a', p = last, np = ++cnt;
    step[last = np] = x, right[np] = 1;
    while (p && !ch[p][pro]) ch[p][pro] = np, p = fa[p];
    if (!p)
      fa[np] = root;
    else {
      int q = ch[p][pro];
      if (step[q] == step[p] + 1)
        fa[np] = q;
      else {
        int nq = ++cnt;
        step[nq] = step[p] + 1;
        memcpy(ch[nq], ch[q], sizeof(ch[q]));
        fa[nq] = fa[q], fa[q] = fa[np] = nq;
        while (ch[p][pro] == q) ch[p][pro] = nq, p = fa[p];
      }
    }
  }
  int pro[N];
  void calright() {
    memset(pro, 0, sizeof(pro));
    for (int i = 1; i <= cnt; i++) pro[step[i]]++;
    for (int i = 1; i <= n; i++) pro[i] += pro[i - 1];
    for (int i = cnt; i; i--) num[pro[step[i]]--] = i;
    for (int i = cnt; i; i--) right[fa[num[i]]] += right[num[i]];
  }
  void run() {
    scanf(" %s", s + 1), n = strlen(s + 1);
    for (int i = 1; i <= n; i++) add(i);
    calright();
  }
  char str[N];
  int len;
  set<int> S;
  long long solve() {
    scanf(" %s", str + 1), len = strlen(str + 1);
    for (int i = 1; i <= len; ++i) str[i + len] = str[i];
    int now = root, tmp = 0;
    long long ans = 0;
    for (int i = 1; i <= len + len; ++i) {
      int x = str[i] - 'a';
      if (ch[now][x])
        now = ch[now][x], ++tmp;
      else {
        while (now && !ch[now][x]) now = fa[now];
        if (!now)
          now = root, tmp = 0;
        else
          tmp = step[now] + 1, now = ch[now][x];
      }
      while (now && step[fa[now]] >= len) now = fa[now], tmp = step[now];
      if (tmp >= len) S.insert(now);
    }
    for (set<int>::iterator it = S.begin(); it != S.end(); ++it)
      ans += right[*it];
    S.clear();
    return ans;
  }
} Fe;
int main() {
  Fe.run();
  int q;
  scanf("%d", &q);
  while (q--) {
    printf("%I64d\n", Fe.solve());
  }
}