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 maxn = 1e6 + 5;
const int node = maxn * 2;
char str[maxn * 2];
struct SAM {
  int nxt[node][26];
  int par[node];
  int len[node];
  int cur[node];
  int pos[node];
  int cnt[node];
  int vis[node];
  int S[node];
  int tol, last, rt, top;
  int newNode(int l) {
    memset(nxt[tol], -1, sizeof nxt[tol]);
    len[tol] = l;
    par[tol] = -1;
    return tol++;
  }
  void init() {
    tol = rt = 0;
    last = newNode(0);
  }
  void add(int c) {
    int p = last;
    int np = newNode(len[p] + 1);
    while (p != -1 && nxt[p][c] == -1) {
      nxt[p][c] = np;
      p = par[p];
    }
    if (p == -1)
      par[np] = rt;
    else {
      int q = nxt[p][c];
      if (len[p] + 1 == len[q])
        par[np] = q;
      else {
        int nq = newNode(len[p] + 1);
        memcpy(nxt[nq], nxt[q], sizeof nxt[q]);
        par[nq] = par[q];
        par[q] = par[np] = nq;
        while (p != -1 && nxt[p][c] == q) {
          nxt[p][c] = nq;
          p = par[p];
        }
      }
    }
    last = np;
  }
  void get_right(char s[]) {
    for (int i = 0; i < tol; i++) cur[i] = cnt[i] = 0;
    for (int i = 0; i < tol; i++) cur[len[i]]++;
    for (int i = 1; i < tol; i++) cur[i] += cur[i - 1];
    for (int i = 0; i < tol; i++) pos[--cur[len[i]]] = i;
    int now = rt;
    for (int i = 0; s[i]; i++) cnt[now = nxt[now][s[i] - 'a']]++;
    for (int i = tol - 1; i >= 0; i--) {
      int u = pos[i];
      cnt[par[u]] += cnt[u];
    }
  }
  int cal(char s[]) {
    int now = rt, maxlen = 0;
    int n = strlen(s);
    for (int i = 0; i < n; i++) {
      s[i + n] = s[i];
    }
    s[2 * n - 1] = '\0';
    top = 0;
    int ans = 0;
    for (int i = 0, c; s[i]; i++) {
      c = s[i] - 'a';
      if (nxt[now][c] != -1) {
        now = nxt[now][c];
        maxlen++;
      } else {
        while (now != -1 && nxt[now][c] == -1) now = par[now];
        if (now == -1) {
          now = rt;
          maxlen = 0;
        } else {
          maxlen = len[now] + 1;
          now = nxt[now][c];
        }
      }
      if (maxlen >= n) {
        while (par[now] != -1 && len[par[now]] + 1 > n) now = par[now];
        if (!vis[now]) {
          ans += cnt[now];
          vis[now] = 1;
          S[++top] = now;
        }
      }
    }
    while (top) vis[S[top--]] = 0;
    return ans;
  }
} gao;
int main() {
  scanf("%s", str);
  gao.init();
  for (int i = 0; str[i]; i++) gao.add(str[i] - 'a');
  gao.get_right(str);
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", str);
    printf("%d\n", gao.cal(str));
  }
  return 0;
}