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 son[2000001][26], fa[2000001], size[2000001], len[2000001],
    cnt = 1, last = 1, n, Q, tax[2000001], pos[2000001], P = 998244353,
    queue[2000001], t;
bool vis[2000001];
char str[2000001];
void add(int x) {
  int p = last;
  size[last = ++cnt] = 1;
  len[last] = n;
  for (; p && !son[p][x]; p = fa[p]) son[p][x] = last;
  if (!p) return (void)(fa[last] = 1);
  int q = son[p][x];
  if (len[q] == len[p] + 1) return (void)(fa[last] = q);
  len[++cnt] = len[p] + 1;
  fa[cnt] = fa[q];
  fa[q] = fa[last] = cnt;
  for (int i = 0; i < 26; i++) son[cnt][i] = son[q][i];
  for (; son[p][x] == q; p = fa[p]) son[p][x] = cnt;
}
int min(int a, int b) { return a < b ? a : b; }
bool allsame() {
  for (int i = 2; i <= n; i++)
    if (str[i] != str[i - 1]) return 0;
  return 1;
}
int qsm(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (long long)ans * a % P;
    a = (long long)a * a % P;
    b >>= 1;
  }
  return ans;
}
int main() {
  scanf("%s", str + 1);
  for (n = 1; str[n]; n++) add(str[n] - 'a');
  for (int i = 1; i <= cnt; i++) tax[len[i]]++;
  for (int i = 1; i <= n; i++) tax[i] += tax[i - 1];
  for (int i = cnt; i; i--) pos[tax[len[i]]--] = i;
  for (int i = cnt; i; i--) size[fa[pos[i]]] += size[pos[i]];
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%s", str + 1);
    n = strlen(str + 1);
    for (int i = 1; i <= n; i++) str[i + n] = str[i] = str[i] - 'a';
    int p = 1, length = 0;
    long long ans = 0;
    for (int i = 1; i < n << 1; i++) {
      while (p && !son[p][str[i]]) p = fa[p];
      if (!p)
        p = 1, length = 0;
      else
        length = min(length, len[p]) + 1, p = son[p][str[i]];
      if (i < n) continue;
      while (len[fa[p]] >= n) p = fa[p];
      length = min(length, len[p]);
      if (length >= n) {
        if (vis[p]) break;
        ans += size[p], vis[p] = 1, queue[++t] = p;
      }
    }
    for (int i = 1; i <= t; i++) vis[queue[i]] = 0;
    t = 0;
    printf("%lld\n", ans);
  }
}