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;
int m, n, L, cnt, sum[1000005];
char s[1000005], x[1000005];
struct Node {
  Node *par, *go[26];
  int val, sum, flag, num;
  void Clear(int _val) {
    par = NULL;
    for (int i = 0; i < 26; i++) go[i] = NULL;
    sum = flag = 0;
    val = _val;
  }
} * root, *last, *a[1000005 * 2], *b[1000005 * 2];
void Extend(int w) {
  Node *p = last, *np = new Node;
  a[++cnt] = np;
  np->num = cnt;
  np->Clear(p->val + 1);
  for (; p && (!(p->go[w])); p = p->par) p->go[w] = np;
  if (!p)
    np->par = root;
  else {
    Node *q = p->go[w];
    if (q->val == p->val + 1)
      np->par = q;
    else {
      Node *nq = new Node;
      a[++cnt] = nq;
      nq->num = cnt;
      nq->Clear(p->val + 1);
      for (int i = 0; i < 26; i++) nq->go[i] = q->go[i];
      nq->par = q->par;
      q->par = np->par = nq;
      for (; p && (p->go[w] == q); p = p->par) p->go[w] = nq;
    }
  }
  last = np;
}
void BuildSAM() {
  scanf("%s", &s);
  m = strlen(s);
  cnt = 0;
  root = new Node;
  root->Clear(0);
  root->num = 0;
  last = root;
  for (int i = 0; i < m; i++) Extend(s[i] - 'a');
}
void DP() {
  for (Node *p = last; p; p = p->par) p->sum = 1;
  for (int i = 0; i <= m; i++) sum[i] = 0;
  for (int i = 1; i <= cnt; i++) sum[a[i]->val]++;
  for (int i = 1; i <= m; i++) sum[i] += sum[i - 1];
  for (int i = 1; i <= cnt; i++) b[sum[a[i]->val]--] = a[i];
  for (int i = cnt; i >= 1; i--) {
    Node *p = b[i];
    for (int j = 0; j < 26; j++)
      if (p->go[j]) {
        p->sum += p->go[j]->sum;
      }
  }
}
int main() {
  BuildSAM();
  DP();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", &x);
    L = strlen(x);
    Node *p = root;
    int len = 0;
    for (int j = 0; j < L; j++) {
      int w = x[j] - 'a';
      while (p && (!p->go[w])) p = p->par;
      if (!p) p = root;
      len = min(len, p->val);
      if (p->go[w]) {
        p = p->go[w];
        len++;
      }
    }
    int ans = 0;
    for (int j = 0; j < L; j++) {
      int w = x[j] - 'a';
      while (p && (!p->go[w])) p = p->par;
      if (!p) {
        p = root;
        continue;
      }
      len = min(len + 1, p->val + 1);
      p = p->go[w];
      while (p->par && (p->par->val >= L)) p = p->par;
      if (p->flag == i) continue;
      if (len >= L) {
        ans += p->sum;
        p->flag = i;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}