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;
inline int rd() {
  register int res = 0, f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * f;
}
int n, m;
char c[2000010];
struct node {
  int tr[26];
  int par, maxl;
} s[2000010];
int ptr = 1, root = 1, last = 1;
int newnode(int l) {
  int k = ++ptr;
  s[k].maxl = l;
  return k;
}
int siz[2000010];
void extend(int k) {
  int p = last;
  int np = newnode(s[p].maxl + 1);
  ++siz[np];
  for (; p && s[p].tr[k] == 0; p = s[p].par) s[p].tr[k] = np;
  if (p == 0)
    s[np].par = root;
  else {
    int q = s[p].tr[k];
    if (s[p].maxl + 1 == s[q].maxl)
      s[np].par = q;
    else {
      int nq = newnode(s[p].maxl + 1);
      memcpy(s[nq].tr, s[q].tr, sizeof(s[q].tr));
      s[nq].par = s[q].par;
      s[q].par = s[np].par = nq;
      for (; p && s[p].tr[k] == q; p = s[p].par) s[p].tr[k] = nq;
    }
  }
  last = np;
  return;
}
int w[2000010], p[2000010];
int vis[2000010], tim = 0;
int main() {
  scanf("%s", c + 1);
  n = strlen(c + 1);
  for (int i = 1; i <= n; ++i) extend(c[i] - 'a');
  for (int i = 1; i <= ptr; ++i) ++w[s[i].maxl];
  for (int i = 1; i <= n; ++i) w[i] += w[i - 1];
  for (int i = ptr; i >= 1; --i) p[w[s[i].maxl]--] = i;
  for (int i = ptr; i >= 1; --i) {
    int k = p[i];
    siz[s[k].par] += siz[k];
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%s", c + 1);
    int l = strlen(c + 1);
    for (int i = l + 1; i < 2 * l; ++i) c[i] = c[i - l];
    ++tim;
    int cur = root, matchlen = 0;
    int ans = 0;
    for (int i = 1; i < 2 * l; ++i) {
      if (s[cur].tr[c[i] - 'a'] != 0) {
        ++matchlen;
        cur = s[cur].tr[c[i] - 'a'];
      } else {
        while (cur && s[cur].tr[c[i] - 'a'] == 0) {
          cur = s[cur].par;
          matchlen = s[cur].maxl;
        }
        if (s[cur].tr[c[i] - 'a'] != 0) {
          ++matchlen;
          cur = s[cur].tr[c[i] - 'a'];
        }
      }
      while (matchlen > l && s[s[cur].par].maxl >= l) cur = s[cur].par;
      if (matchlen >= l && vis[cur] != tim) {
        ans += siz[cur];
        vis[cur] = tim;
      }
    }
    cout << ans << endl;
  }
  return 0;
}