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;
const int S = 26;
char a[N + 3];
char b[(N << 1) + 3];
int son[(N << 1) + 3][S + 3];
int fa[(N << 1) + 3];
int len[(N << 1) + 3];
int vis[(N << 1) + 3];
int ord[(N << 1) + 3];
int buc[N + 3];
int nxt[N + 3];
int sz[(N << 1) + 3];
int n, q, m, siz, rtn, lstpos;
void initSAM() { siz = rtn = lstpos = 1; }
void KMP() {
  nxt[0] = nxt[1] = 0;
  for (int i = 2; i <= m; i++) {
    nxt[i] = nxt[i - 1];
    while (nxt[i] && b[nxt[i] + 1] != b[i]) {
      nxt[i] = nxt[nxt[i]];
    }
    if (b[nxt[i] + 1] == b[i]) nxt[i]++;
  }
}
void insertchar(char ch) {
  int p = lstpos, np;
  siz++;
  np = lstpos = siz;
  len[np] = len[p] + 1;
  sz[np]++;
  for (; p && son[p][ch] == 0; p = fa[p]) {
    son[p][ch] = np;
  }
  if (p == 0) {
    fa[np] = rtn;
  } else {
    int q = son[p][ch];
    if (len[q] == len[p] + 1) {
      fa[np] = q;
    } else {
      siz++;
      int nq = siz;
      len[nq] = len[p] + 1;
      memcpy(son[nq], son[q], sizeof(son[q]));
      fa[nq] = fa[q];
      fa[q] = fa[np] = nq;
      for (; p && son[p][ch] == q; p = fa[p]) {
        son[p][ch] = nq;
      }
    }
  }
}
int main() {
  initSAM();
  scanf("%s", a + 1);
  n = strlen(a + 1);
  for (int i = 1; i <= n; i++) a[i] -= 96;
  for (int i = 1; i <= n; i++) {
    insertchar(a[i]);
  }
  for (int i = 1; i <= siz; i++) buc[len[i]]++;
  for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
  for (int i = siz; i >= 1; i--) ord[buc[len[i]]--] = i;
  for (int i = siz; i >= 1; i--) {
    int u = ord[i];
    sz[fa[u]] += sz[u];
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%s", b + 1);
    m = strlen(b + 1);
    for (int i = 1; i <= m; i++) b[i] -= 96;
    KMP();
    int cyclen = nxt[m];
    while (cyclen > 0 && m % (m - cyclen) != 0) {
      cyclen = nxt[cyclen];
    }
    cyclen = m - cyclen;
    for (int i = 1; i < cyclen; i++) b[i + m] = b[i];
    int u = rtn, cur = 0, ans = 0;
    for (int i = 1; i < m + cyclen; i++) {
      while (u && son[u][b[i]] == 0) {
        u = fa[u];
        cur = len[u];
      }
      if (son[u][b[i]] != 0) {
        u = son[u][b[i]];
        cur++;
      } else {
        u = rtn;
        cur = 0;
      }
      if (cur == m) {
        ans += sz[u];
        cur--;
        if (cur <= len[fa[u]]) {
          u = fa[u];
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}