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 = 1000005;
const int SIZE = maxn << 1;
char str[maxn];
struct SAM {
  int nxt[SIZE][26], par[SIZE], len[SIZE];
  int cur[SIZE], pos[SIZE], g[SIZE], vis[SIZE], S[SIZE];
  int root, last, tol, top;
  int newNode(int x) {
    len[tol] = x;
    par[tol] = -1;
    memset(nxt[tol], -1, sizeof nxt[tol]);
    return tol++;
  }
  void Init() {
    root = tol = 0;
    last = newNode(0);
  }
  void add(int k) {
    int p = last;
    int np = newNode(len[p] + 1);
    while (p != -1 && nxt[p][k] == -1) {
      nxt[p][k] = np;
      p = par[p];
    }
    if (p == -1)
      par[np] = root;
    else {
      int q = nxt[p][k];
      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][k] == q) {
          nxt[p][k] = nq;
          p = par[p];
        }
      }
    }
    last = np;
  }
  void ins(char s[]) {
    for (int i = 0; s[i]; i++) {
      add(s[i] - 'a');
    }
  }
  void get_right(char s[]) {
    memset(cur, 0, sizeof cur);
    memset(g, 0, sizeof g);
    memset(vis, 0, sizeof vis);
    for (int i = 0; i < tol; i++) cur[len[i]]++;
    for (int i = 0; i < tol; i++) cur[i] += cur[i - 1];
    for (int i = 0; i < tol; i++) pos[--cur[len[i]]] = i;
    int now = root;
    for (int i = 0; s[i]; i++) g[now = nxt[now][s[i] - 'a']]++;
    for (int i = tol - 1; i >= 0; i--) {
      int u = pos[i];
      g[par[u]] += g[u];
    }
  }
  int Count(char s[]) {
    int now = root, maxlen = 0;
    int l = strlen(s), ans = 0;
    top = 0;
    for (int i = 0; i < l; i++) {
      s[i + l] = s[i];
    }
    s[l << 1] = '\0';
    for (int i = 0, k; s[i]; i++) {
      k = s[i] - 'a';
      if (nxt[now][k] != -1) {
        maxlen++;
        now = nxt[now][k];
        int t = now;
        while (par[t] != -1 && len[par[t]] >= l) t = par[t];
        if (maxlen >= l && !vis[t]) {
          ans += g[t];
          vis[t] = 1;
          S[++top] = t;
        }
      } else {
        while (now != -1 && nxt[now][k] == -1) now = par[now];
        if (now == -1) {
          now = root;
          maxlen = 0;
        } else {
          maxlen = len[now] + 1;
          now = nxt[now][k];
          int t = now;
          while (par[t] != -1 && len[par[t]] >= l) t = par[t];
          if (maxlen >= l && !vis[t]) {
            ans += g[t];
            vis[t] = 1;
            S[++top] = t;
          }
        }
      }
    }
    while (top) vis[S[top--]] = 0;
    return ans;
  }
} sam;
int main() {
  int n;
  while (scanf("%s", str) != EOF) {
    sam.Init();
    sam.ins(str);
    sam.get_right(str);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%s", str);
      printf("%d\n", sam.Count(str));
    }
  }
  return 0;
}