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 N, M;
int len, ans, flag;
int deb;
int p[1000005];
char ss[1000005];
string s[1000005];
struct node {
  int sum, mx, vis;
  node *par, *son[26], *st, *next;
  node(int x = 0) : mx(x) {
    sum = vis = 0, memset(son, 0, sizeof(son)), par = st = next = 0;
  }
};
struct SAM {
  node *root, *p, *np, *end;
  node *q, *nq;
  void build() { root = end = new node(0); }
  int idx(char c) { return c - 'a'; }
  void Insert(char c) {
    int i;
    p = end, end = new node(p->mx + 1);
    c = idx(c), end->sum += flag;
    while (p && !p->son[c]) p->son[c] = end, p = p->par;
    if (!p)
      end->par = root;
    else {
      q = p->son[c];
      if (q->mx == p->mx + 1)
        end->par = q;
      else {
        nq = new node(p->mx + 1);
        memcpy(nq->son, q->son, sizeof(q->son));
        nq->par = q->par, q->par = end->par = nq;
        while (p && p->son[c] == q) p->son[c] = nq, p = p->par;
      }
    }
  }
  void Dfs(node* x) {
    int i;
    node* tmp;
    x->vis = -1;
    if (x->par) x->next = x->par->st, x->par->st = x;
    for (i = 0; i < 26; i++) {
      tmp = x->son[i];
      if (!tmp) continue;
      if (!tmp->vis) Dfs(tmp);
    }
  }
  void Find(node* x) {
    node* tmp;
    for (tmp = x->st; tmp != NULL; tmp = tmp->next) {
      Find(tmp);
      x->sum += tmp->sum;
    }
  }
} S;
int main() {
  int i, j, len, fr;
  scanf("%s", ss);
  len = strlen(ss), flag = 1;
  S.build();
  for (i = 0; i < len; i++) S.Insert(ss[i]);
  scanf("%d", &N), flag = 0;
  for (i = 1; i <= N; i++) {
    cin >> s[i];
    p[i] = s[i].length(), ans = 0;
    s[i].resize(p[i] * 2);
    for (j = 0; j < p[i]; j++) s[i][p[i] + j] = s[i][j];
  }
  S.Dfs(S.root);
  S.Find(S.root);
  for (i = 1; i <= N; i++) {
    node* now = S.root;
    ans = 0;
    for (j = 0, len = 0; j < p[i]; j++, len++) {
      if (now->son[s[i][j] - 'a'])
        now = now->son[s[i][j] - 'a'];
      else
        break;
    }
    fr = j;
    for (j = 0; j < p[i]; j++) {
      if (len == p[i] && now->vis != i) ans += now->sum, now->vis = i;
      if (j != p[i] - 1) {
        if (len) {
          if (now->par->mx < len - 1)
            now = now;
          else
            now = now->par;
          len--;
        }
        while (len < p[i] && now->son[s[i][fr] - 'a']) {
          if (len == p[i]) break;
          now = now->son[s[i][fr] - 'a'], len++, fr++;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}