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 N = 2e6 + 5;
int last = 1, tot = 1, size[N], len[N], fa[N], ch[N][26], n;
int tax[N], c[N], q;
char s[N];
void samAdd(int val) {
  int cur = ++tot, pre = last;
  last = cur;
  size[cur] = 1;
  len[cur] = len[pre] + 1;
  while (pre && !ch[pre][val]) ch[pre][val] = cur, pre = fa[pre];
  if (!pre) return void(fa[cur] = 1);
  int x = ch[pre][val];
  if (len[pre] + 1 == len[x]) return void(fa[cur] = x);
  int y = ++tot;
  fa[y] = fa[x];
  fa[x] = fa[cur] = y;
  len[y] = len[pre] + 1;
  memcpy(ch[y], ch[x], sizeof(ch[x]));
  while (pre && ch[pre][val] == x) ch[pre][val] = y, pre = fa[pre];
}
int rec[N], p[N];
int query(char *s, int d) {
  int x = 1, n = strlen(s), lcs = 0, ret = 0;
  for (int i = n; i < n << 1; ++i) s[i] = s[i - n];
  for (int i = 0; i < n << 1; ++i) {
    int c = s[i] - 'a';
    while (x && !ch[x][c]) x = fa[x], lcs = len[x];
    if (!x)
      x = 1, lcs = 0;
    else {
      x = ch[x][c];
      ++lcs;
      while (x && len[fa[x]] >= n) x = fa[x], lcs = len[x];
      if (lcs >= n && rec[x] != d) ret += size[x], rec[x] = d;
    }
  }
  return ret;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; ++i) samAdd(s[i] - 'a');
  for (int i = 1; i <= tot; ++i) ++tax[len[i]];
  for (int i = 1; i <= tot; ++i) tax[i] += tax[i - 1];
  for (int i = 1; i <= tot; ++i) c[tax[len[i]]--] = i;
  for (int i = tot; i; --i) size[fa[c[i]]] += size[c[i]];
  scanf("%d", &q);
  while (q--) scanf("%s", s), printf("%d\n", query(s, q + 1));
  return 0;
}