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;
int len, n, ls, tail, gs = 0;
int lab[1000010 * 2];
struct node {
  int par, len, hs, f;
  int c[27];
} tr[1000010 * 2];
void insert(int c, int len) {
  int now = tail, tmp, r;
  tr[tail = ++gs].len = len;
  for (; now > -1 && !tr[now].c[c]; now = tr[now].par) tr[now].c[c] = tail;
  if (now == -1)
    tr[tail].par = 0;
  else {
    tmp = tr[now].c[c];
    if (tr[tmp].len == tr[now].len + 1)
      tr[tail].par = tmp;
    else {
      tr[r = ++gs] = tr[tmp];
      tr[r].len = tr[now].len + 1;
      tr[tmp].par = tr[tail].par = r;
      for (; now > -1 && tr[now].c[c] == tmp; now = tr[now].par)
        tr[now].c[c] = r;
    }
  }
}
void build(char s[], int len) {
  tail = 0;
  tr[0].par = -1;
  for (int i = 0; i < len; ++i) insert(s[i] - 'a', i + 1);
}
bool cmp(int x, int y) { return tr[x].len < tr[y].len; }
int find(char s[], int len, int ti) {
  int now = 0, nl = 0, ans = 0;
  for (int i = 0; i < len * 2; ++i) {
    while (now > 0 && tr[now].c[s[i] - 'a'] == 0)
      now = tr[now].par, nl = tr[now].len;
    if (tr[now].c[s[i] - 'a'] > 0) now = tr[now].c[s[i] - 'a'], ++nl;
    if (i >= len - 1) {
      while (now > 0 && tr[now].par > 0 && tr[tr[now].par].len >= len)
        now = tr[now].par, nl = tr[now].len;
      if (nl >= len && now > 0 && tr[now].hs != ti) {
        tr[now].hs = ti;
        ans += tr[now].f;
      }
    }
  }
  return ans;
}
char s[1000010 * 2];
int main() {
  scanf("%s", s);
  len = strlen(s);
  build(s, len);
  for (int i = 1; i <= gs; ++i) lab[i] = i;
  sort(lab + 1, lab + 1 + gs, cmp);
  int tmp = lab[gs];
  while (tmp != 0) tr[tmp].f = 1, tmp = tr[tmp].par;
  tr[0].f = 1;
  for (int i = gs; i > 0; --i) {
    int x = lab[i];
    for (int j = 0; j < 26; ++j)
      if (tr[x].c[j]) tr[x].f += tr[tr[x].c[j]].f;
  }
  scanf("%d", &n);
  getchar();
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s);
    ls = strlen(s);
    memmove(s + ls, s, ls);
    s[ls * 2] = 0;
    printf("%d\n", find(s, ls, i));
  }
  return 0;
}