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;
inline int read() {
  int x = 0, y = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') y = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return y ? -x : x;
}
int son[2000005][26], fa[2000005], siz[2000005], cur[2000005], tax[2000005],
    len[2000005], seg[2000005], cnt = 1, last = 1;
char s[2000005];
void insert(int c) {
  int p = last, ne = last = ++cnt;
  len[ne] = len[p] + 1, siz[ne] = 1;
  while (p && !son[p][c]) son[p][c] = ne, p = fa[p];
  if (!p)
    fa[ne] = 1;
  else {
    int q = son[p][c];
    if (len[q] == len[p] + 1)
      fa[ne] = q;
    else {
      int sp = ++cnt;
      memcpy(son[sp], son[q], sizeof son[q]);
      fa[sp] = fa[q], len[sp] = len[p] + 1, fa[q] = fa[ne] = sp;
      while (p && son[p][c] == q) son[p][c] = sp, p = fa[p];
    }
  }
}
signed main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1), m = read();
  for (register int i = 1; i <= n; ++i) insert(s[i] - 'a');
  for (register int i = 1; i <= cnt; ++i) ++tax[len[i]];
  for (register int i = 1; i <= n; ++i) tax[i] += tax[i - 1];
  for (register int i = 1; i <= cnt; ++i) cur[tax[len[i]]--] = i;
  for (register int i = cnt; i > 1; --i) {
    int x = cur[i];
    siz[fa[x]] += siz[x];
  }
  for (register int t = 1; t <= m; ++t) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    int node = 1, l = 0;
    long long ans = 0;
    for (register int i = 1; i <= n; ++i) {
      while (node && !son[node][s[i] - 'a']) node = fa[node], l = len[node];
      node = son[node][s[i] - 'a'], ++l;
    }
    for (register int i = 1; i <= n; ++i) {
      while (node && !son[node][s[i] - 'a']) node = fa[node], l = len[node];
      node = son[node][s[i] - 'a'], ++l;
      while (node && len[fa[node]] >= n) node = fa[node], l = len[node];
      if (l >= n && seg[node] < t) ans += siz[node], seg[node] = t;
    }
    printf("%lld\n", ans);
  }
}