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;
const int maxn = 2100000;
int ch[maxn][26], len[maxn], fail[maxn], tail, cnt;
int ind[maxn], vis[maxn], num[maxn];
void ins(int c) {
  int t = tail;
  tail = ++cnt;
  len[cnt] = len[t] + 1;
  while (t && !ch[t][c]) ch[t][c] = cnt, t = fail[t];
  if (!t && !ch[t][c]) {
    ch[0][c] = cnt;
    fail[cnt] = 0;
    return;
  }
  if (len[ch[t][c]] == len[t] + 1)
    fail[cnt] = ch[t][c];
  else {
    int i = ++cnt, j = ch[t][c];
    fail[i] = fail[j], fail[j] = fail[tail] = i;
    len[i] = len[t] + 1;
    memcpy(ch[i], ch[j], sizeof(ch[0]));
    for (; t && ch[t][c] == j; t = fail[t]) ch[t][c] = i;
    if (ch[0][c] == j) ch[0][c] = i;
  }
}
char s[2100000];
int cmp(int a, int b) { return len[a] < len[b]; }
int main() {
  scanf("%s", s);
  int n, i, j, l;
  l = strlen(s);
  for (i = 0; i < l; i++) ins(s[i] - 'a');
  for (i = 1; i <= cnt; i++) ind[i] = i;
  sort(ind + 1, ind + 1 + cnt, cmp);
  while (tail) num[tail] = 1, tail = fail[tail];
  for (i = cnt; i >= 1; i--)
    for (j = 0; j < 26; j++) num[ind[i]] += num[ch[ind[i]][j]];
  scanf("%d", &n);
  int ii = 0;
  while (n--) {
    ii++;
    scanf("%s", s);
    l = strlen(s);
    int now = 0, ll = 0, ans = 0;
    memmove(s + l, s, l);
    l <<= 1;
    for (i = 0; i < l; i++) {
      while (now && !ch[now][s[i] - 'a']) now = fail[now], ll = len[now];
      now = ch[now][s[i] - 'a'];
      if (now) ll++;
      while (len[fail[now]] >= (l >> 1)) now = fail[now], ll = len[now];
      if (ll >= (l >> 1) && vis[now] - ii) {
        vis[now] = ii;
        ans += num[now];
      }
    }
    printf("%d\n", ans);
  }
}