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 = 1e6 + 100, M = 2 * N;
char str[N];
string str2;
int n, last = 1, tot = 1;
int h[M], ne[M], e[M], idx;
long long f[M];
bool st[M];
int recover[M], cnt;
struct node {
  int fa, len;
  int ch[26];
} tr[M];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
void dfs(int u) {
  for (int i = h[u]; ~i; i = ne[i]) {
    int j = e[i];
    dfs(j);
    f[u] += f[j];
  }
}
void extend(int c) {
  int p = last, np = last = ++tot;
  tr[np].len = tr[p].len + 1;
  f[tot] = 1;
  for (; p && !tr[p].ch[c]; p = tr[p].fa) tr[p].ch[c] = np;
  if (!p)
    tr[np].fa = 1;
  else {
    int q = tr[p].ch[c];
    if (tr[q].len == tr[p].len + 1)
      tr[np].fa = q;
    else {
      int nq = ++tot;
      tr[nq] = tr[q], tr[nq].len = tr[p].len + 1;
      tr[np].fa = tr[q].fa = nq;
      for (; p && tr[p].ch[c] == q; p = tr[p].fa) tr[p].ch[c] = nq;
    }
  }
}
int main() {
  scanf("%s", str), scanf("%d", &n);
  for (int i = 0; str[i]; i++) extend(str[i] - 'a');
  memset(h, -1, sizeof h);
  for (int i = 2; i <= tot; i++) add(tr[i].fa, i);
  dfs(1);
  for (int i = 1; i <= n; i++) {
    cin >> str2;
    cnt = 0;
    int len = str2.length();
    str2 = str2 + str2;
    int l = 0, r = 0, pos = 1, res = 0;
    while (l <= len - 1) {
      while (tr[pos].ch[str2[r] - 'a'] && r - l + 1 <= len) {
        pos = tr[pos].ch[str2[r] - 'a'], r++;
      }
      if (r - l + 1 == len + 1 && !st[pos]) {
        res += f[pos];
        st[pos] = true;
        recover[++cnt] = pos;
      }
      l++;
      if (r - l + 1 == tr[tr[pos].fa].len + 1) {
        pos = tr[pos].fa;
      }
      if (r <= 2 * len - 1) {
        while (pos != 1 && !tr[pos].ch[str2[r] - 'a']) {
          pos = tr[pos].fa;
          int tem = tr[pos].len;
          l = r - tem;
        }
      }
    }
    for (int i = 1; i <= cnt; i++) st[recover[i]] = false;
    printf("%d\n", res);
  }
  return 0;
}