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 MAX_N = 1000000;
char str[MAX_N + 10];
int sam[MAX_N * 2 + 10][26], tn, par[MAX_N * 2 + 10], dep[MAX_N * 2 + 10], last;
int size[MAX_N * 2 + 10];
queue<int> q;
bool tag[MAX_N * 2 + 10];
int qn;
void insert(int c) {
  int u = ++tn;
  dep[u] = dep[last] + 1;
  size[u] = 1;
  int cur;
  for (cur = last; cur != -1 && !sam[cur][c]; cur = par[cur]) sam[cur][c] = u;
  if (cur == -1)
    par[u] = 0;
  else {
    int t = sam[cur][c];
    if (dep[t] == dep[cur] + 1)
      par[u] = t;
    else {
      int v = ++tn;
      par[v] = par[t];
      dep[v] = dep[cur] + 1;
      par[t] = par[u] = v;
      for (int i = 0; i < 26; i++) sam[v][i] = sam[t][i];
      for (; cur != -1 && sam[cur][c] == t; cur = par[cur]) sam[cur][c] = v;
    }
  }
  last = u;
}
int pos[MAX_N + 10], pn;
int deg[MAX_N * 2 + 10];
int main() {
  scanf("%s", str);
  par[0] = -1;
  for (int i = 0; str[i] != '\0'; i++) insert(str[i] - 'a');
  for (int i = 1; i <= tn; i++) ++deg[par[i]];
  for (int i = 0; i <= tn; i++)
    if (!deg[i]) q.push(i);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    if (cur) {
      size[par[cur]] += size[cur];
      --deg[par[cur]];
      if (deg[par[cur]] == 0) q.push(par[cur]);
    }
  }
  scanf("%d", &qn);
  while (qn--) {
    scanf("%s", str);
    int len = strlen(str);
    int cur = 0, mlen = 0;
    for (int i = 0; i < len; i++) {
      int g = str[i] - 'a';
      for (; cur != -1 && !sam[cur][g]; cur = par[cur])
        if (cur && dep[par[cur]] < mlen) mlen = dep[par[cur]];
      if (cur == -1) {
        cur = 0;
        mlen = 0;
      } else {
        cur = sam[cur][g];
        ++mlen;
      }
    }
    pn = 0;
    int ans = 0;
    for (int i = 0; i < len; i++) {
      int g = str[i] - 'a';
      for (; cur != -1 && !sam[cur][g]; cur = par[cur])
        if (cur && dep[par[cur]] < mlen) mlen = dep[par[cur]];
      if (cur == -1) {
        cur = 0;
        mlen = 0;
      } else {
        cur = sam[cur][g];
        ++mlen;
      }
      if (mlen >= len) {
        while (dep[par[cur]] >= len) cur = par[cur];
        if (!tag[cur]) {
          ans += size[cur];
          tag[cur] = true;
          pos[pn++] = cur;
        }
      }
    }
    for (int i = 0; i < pn; i++) tag[pos[i]] = false;
    printf("%d\n", ans);
  }
  return 0;
}