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 N = 1000010, CHAR = 26;
char s[N];
char x[N];
int nxt[N * 2][CHAR], len[N * 2], suf[N * 2], freeMem, last, sz;
long long cnt[N * 2];
void add(int u) {
  int newNode = ++freeMem;
  len[newNode] = len[last] + 1;
  cnt[newNode] = 1;
  while (last != -1 && nxt[last][u] == -1) {
    nxt[last][u] = newNode;
    last = suf[last];
  }
  if (last == -1) {
    suf[newNode] = 0;
    last = newNode;
    return;
  }
  int q = nxt[last][u];
  if (len[q] == len[last] + 1) {
    suf[newNode] = q;
    last = newNode;
    return;
  }
  int clone = ++freeMem;
  len[clone] = len[last] + 1;
  for (int i = 0; i < CHAR; i++) {
    nxt[clone][i] = nxt[q][i];
  }
  while (last != -1 && nxt[last][u] == q) {
    nxt[last][u] = clone;
    last = suf[last];
  }
  suf[clone] = suf[q];
  suf[q] = suf[newNode] = clone;
  last = newNode;
}
int used[N * 2];
vector<int> adj[N * 2];
void dfs(int u) {
  for (int v : adj[u]) {
    dfs(v);
    cnt[u] += cnt[v];
  }
}
int main() {
  scanf("%s", s + 1);
  sz = strlen(s + 1);
  memset(nxt, -1, sizeof nxt);
  memset(suf, -1, sizeof suf);
  for (int i = 1; i <= sz; i++) {
    add(s[i] - 'a');
  }
  for (int i = 1; i <= freeMem; i++) {
    adj[suf[i]].push_back(i);
  }
  dfs(0);
  int n;
  scanf("%d", &n);
  for (int ii = 1; ii <= n; ii++) {
    scanf("%s", x + 1);
    int l = strlen(x + 1);
    int cur = 0, res = 0, curLen = 0;
    for (int i = 1; i <= l; i++) {
      int u = x[i] - 'a';
      while (cur != -1 && nxt[cur][u] == -1) {
        cur = suf[cur];
        curLen = len[cur];
      }
      if (cur == -1) {
        cur = 0;
        curLen = 0;
      } else {
        cur = nxt[cur][u];
        curLen++;
      }
    }
    for (int i = 1; i <= l; i++) {
      int u = x[i] - 'a';
      while (cur != -1 && nxt[cur][u] == -1) {
        cur = suf[cur];
        curLen = len[cur];
      }
      if (cur == -1) {
        cur = 0;
        curLen = 0;
      } else {
        cur = nxt[cur][u];
        curLen++;
        while (suf[cur] != -1 && len[suf[cur]] >= l) {
          cur = suf[cur];
          curLen = len[cur];
        }
      }
      if (curLen >= l && used[cur] != ii) {
        used[cur] = ii;
        res += cnt[cur];
      }
    }
    printf("%d\n", res);
  }
  return 0;
}