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 double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 2e6 + 5;
const double eps = 1e-9;
using namespace std;
char str[MAXN], tmp[MAXN];
int a[MAXN][26], last = 1, sz = 1, b[MAXN], st[MAXN];
int len[MAXN], par[MAXN], cnt[MAXN], t[MAXN];
bool inStack[MAXN];
void add(int x) {
  int pre = last;
  int npre = last = ++sz;
  len[npre] = len[pre] + 1;
  while (pre > 0 && a[pre][x] == 0) a[pre][x] = npre, pre = par[pre];
  if (pre == 0) {
    par[npre] = 1;
    return;
  }
  int q = a[pre][x];
  if (len[pre] + 1 == len[q]) {
    par[npre] = q;
    return;
  }
  int nq = ++sz;
  len[nq] = len[pre] + 1;
  for (int i = 0; i < 26; i++) a[nq][i] = a[q][i];
  par[nq] = par[q];
  par[npre] = par[q] = nq;
  while (a[pre][x] == q) a[pre][x] = nq, pre = par[pre];
}
int main() {
  scanf("%s", str + 1);
  int n = strlen(str + 1), q;
  for (int i = 1; i <= n; i++) add(str[i] - 'a');
  for (int i = 1, pre = 1; i <= n; i++) pre = a[pre][str[i] - 'a'], cnt[pre]++;
  for (int i = 1; i <= sz; i++) b[len[i]]++;
  for (int i = 1; i <= n; i++) b[i] += b[i - 1];
  for (int i = 1; i <= sz; i++) t[b[len[i]]--] = i;
  for (int i = sz; i > 0; i--) cnt[par[t[i]]] += cnt[t[i]];
  scanf("%d", &(q));
  for (int w = 0; w < q; w++) {
    scanf("%s", tmp + 1);
    int m = strlen(tmp + 1);
    for (int i = m + 1; i <= 2 * m; i++) tmp[i] = tmp[i - m];
    int pre = 1, x = 0, top = 0;
    for (int i = 1; i < 2 * m; i++) {
      if (a[pre][tmp[i] - 'a'] > 0)
        pre = a[pre][tmp[i] - 'a'], x++;
      else {
        while (pre > 0 && a[pre][tmp[i] - 'a'] == 0) pre = par[pre];
        if (pre == 0)
          pre = 1, x = 0;
        else
          x = len[pre] + 1, pre = a[pre][tmp[i] - 'a'];
      }
      while (len[par[pre]] >= m) pre = par[pre], x = len[pre];
      if (inStack[pre] == 0 && x >= m) st[++top] = pre, inStack[pre] = 1;
    }
    long long ans = 0;
    for (int i = 1; i <= top; i++) {
      inStack[st[i]] = 0;
      ans += cnt[st[i]];
    }
    printf("%I64d\n", (ans));
  }
  return 0;
}