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 + 10, size = 1 << 20;
template <class o>
void qr(o &x) {
  char c = getchar();
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o>
void pr2(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  puts("");
}
char s[N];
int n, q, len, last = 1, tot = 1, f[N];
int vis[N], num;
struct node {
  int fa, len, v[26];
} tr[N];
void add(int c) {
  int p = last, x = last = ++tot;
  tr[x].len = tr[p].len + 1;
  for (; p && !tr[p].v[c]; p = tr[p].fa) tr[p].v[c] = x;
  if (!p)
    tr[x].fa = 1;
  else {
    int q = tr[p].v[c], y;
    if (tr[p].len + 1 == tr[q].len)
      tr[x].fa = q;
    else {
      tr[y = ++tot] = tr[q];
      tr[y].len = tr[p].len + 1;
      tr[q].fa = tr[x].fa = y;
      for (; p && tr[p].v[c] == q; p = tr[p].fa) tr[p].v[c] = y;
    }
  }
  f[x]++;
}
int b[N], c[N];
void Sort() {
  for (int i = 1; i <= tot; i++) c[tr[i].len]++;
  for (int i = 1; i <= n; i++) c[i] += c[i - 1];
  for (int i = tot; i; i--) b[c[tr[i].len]--] = i;
}
long long ans;
void ins(int c) {
  if (tr[last].v[c])
    n++, last = tr[last].v[c];
  else {
    while (last && !tr[last].v[c]) last = tr[last].fa;
    n = tr[last].len + 1;
    last = tr[last].v[c];
    if (!last) last = 1, n = 0;
  }
}
void del(int c) {
  if (n > len && --n == tr[tr[last].fa].len) last = tr[last].fa;
}
void upd() {
  if ((n == len) && (vis[last] ^ num)) vis[last] = num, ans += f[last];
}
int main() {
  scanf("%s", s + 1);
  for (int i = 1; s[i]; i++) n++, add(s[i] - 'a');
  Sort();
  for (int i = tot; i > 1; i--) {
    int j = b[i];
    f[tr[j].fa] += f[j];
  }
  f[1] = 0;
  qr(q);
  for (num = 1; num <= q; num++) {
    scanf("%s", s + 1);
    len = strlen(s + 1);
    last = 1;
    n = ans = 0;
    for (int i = 1, c; s[i]; i++) {
      c = s[i] - 'a';
      ins(c);
    }
    upd();
    for (int i = 1, c; i < len; i++) {
      c = s[i] - 'a';
      ins(c);
      del(c);
      upd();
    }
    pr2(ans);
  }
  return 0;
}