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 M = 2000001;
int n, m, k, a[M], c[M][26], fa[M], sz[M], cnt = 1, las = 1, vis[M], len[M];
void SAM(int k) {
  int x = ++cnt, y = las;
  las = x, len[x] = len[y] + 1;
  sz[x] = 1;
  for (; y && !c[y][k]; y = fa[y]) c[y][k] = x;
  if (!y) {
    fa[x] = 1;
    return;
  }
  int p = c[y][k];
  if (len[p] == len[y] + 1) {
    fa[x] = p;
    return;
  }
  int np = ++cnt;
  fa[np] = fa[p];
  fa[p] = fa[x] = np;
  memcpy(c[np], c[p], sizeof(c[p]));
  len[np] = len[y] + 1;
  for (; y && c[y][k] == p; y = fa[y]) c[y][k] = np;
}
char s[M];
bool cmp(int x, int y) { return len[x] > len[y]; }
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) SAM(s[i] - 'a');
  for (int i = 1; i <= cnt; i++) a[i] = i;
  sort(a + 1, a + 1 + cnt, cmp);
  for (int i = 1; i <= cnt; i++) sz[fa[a[i]]] += sz[a[i]];
  scanf("%d", &m);
  for (; m; m--) {
    scanf("\n%s", s);
    int ans = 0, L = 0;
    int l = strlen(s), now = 1;
    for (int i = 0; i < l + l; i++) {
      int d = s[i % l] - 'a';
      while (now && !c[now][d]) now = fa[now], L = len[now];
      if (!now)
        now = 1, L = 0;
      else
        now = c[now][d], L++;
      while (len[fa[now]] >= l) now = fa[now], L = len[now];
      if (L >= l && vis[now] != m) {
        vis[now] = m;
        ans += sz[now];
      }
    }
    printf("%d\n", ans);
  }
}