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>
long long ans;
int n, t, k, m, len;
char s[2000005];
struct SAM {
  int ch[2000005][26], step[2000005], pre[2000005], cnt, last, a[2000005],
      b[2000005], sz[2000005], u, l;
  int vis[2000005], id;
  inline void init() {
    memset(ch, 0, sizeof ch);
    memset(a, 0, sizeof a);
    memset(b, 0, sizeof b);
    memset(sz, 0, sizeof sz);
    memset(step, 0, sizeof step);
    memset(pre, 0, sizeof pre);
    cnt = last = 1;
    u = 1, l = 0;
  }
  inline int ins(int x) {
    int p = last;
    if (ch[p][x]) {
      int q = ch[p][x];
      if (step[p] + 1 == step[q]) {
        sz[q]++;
        return q;
      }
      int nq = ++cnt;
      step[nq] = step[p] + 1;
      memcpy(ch[nq], ch[q], sizeof ch[q]);
      pre[nq] = pre[q];
      pre[q] = nq;
      while (ch[p][x] == q) ch[p][x] = nq, p = pre[p];
      sz[nq] = 1;
      return nq;
    }
    int np = ++cnt;
    last = cnt;
    step[np] = step[p] + 1;
    sz[np] = 1;
    while (p && !ch[p][x]) ch[p][x] = np, p = pre[p];
    if (!p)
      pre[np] = 1;
    else {
      int q = ch[p][x];
      if (step[q] == step[p] + 1)
        pre[np] = q;
      else {
        int nq = ++cnt;
        step[nq] = step[p] + 1;
        memcpy(ch[nq], ch[q], sizeof ch[q]);
        pre[nq] = pre[q];
        pre[q] = pre[np] = nq;
        while (ch[p][x] == q) ch[p][x] = nq, p = pre[p];
      }
    }
    return np;
  }
  inline void init2() {
    for (int i = (1); i <= (cnt); ++i) a[step[i]]++;
    for (int i = (1); i <= (cnt); ++i) a[i] += a[i - 1];
    for (int i = (1); i <= (cnt); ++i) b[a[step[i]]--] = i;
    for (int i = (cnt); i >= (1); --i) sz[pre[b[i]]] += sz[b[i]];
    return;
  }
  inline void print() {
    for (int i = (1); i <= (cnt); ++i)
      for (int j = (0); j <= (25); ++j)
        if (ch[i][j]) printf("%d --%c--> %d \n", i, j + 'a', ch[i][j]);
    for (int i = (1); i <= (cnt); ++i) printf("pre[%d] = %d \n", i, pre[i]);
  }
  inline void solve() {
    ++id;
    ans = 0;
    int u = 1;
    l = 0;
    for (int i = (1); i <= (m); ++i) {
      while (u && !ch[u][s[i]]) {
        u = pre[u], l = step[u];
      }
      if (!u) {
        u = 1;
        l = 0;
      } else {
        u = ch[u][s[i]];
        ++l;
      }
      if (i >= n) {
        while (l > n) {
          if (step[pre[u]] >= n) {
            u = pre[u];
            l = step[u];
          } else {
            l = n;
          }
        }
        if (l == n) {
          if (vis[u] != id) {
            vis[u] = id;
            ans += sz[u];
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
} sam;
int main() {
  sam.init();
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = (1); i <= (n); ++i) sam.last = sam.ins(s[i] - 'a');
  scanf("%d", &t);
  sam.init2();
  while (t--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (int i = (1); i <= (n); ++i) s[i] -= 'a';
    for (int i = (n + 1); i <= (2 * n - 1); ++i) s[i] = s[i - n];
    m = 2 * n - 1;
    sam.solve();
  }
  return 0;
}