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;
template <class T>
inline bool checkMax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T, typename... Args>
inline void checkMax(T &a, const Args... arg) {
  checkMax(a, max(arg...));
}
template <class T>
inline bool checkMin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename... Args>
inline void checkMin(T &a, const Args... arg) {
  checkMin(a, min(arg...));
}
const int INF = 0x3f3f3f3f;
const long long llINF = 1e18;
const int MAXN = 2e6 + 5;
int n;
char s[MAXN];
struct SAM {
  int last, tot;
  int son[MAXN][26], len[MAXN], size[MAXN], fa[MAXN], vis[MAXN];
  vector<int> G[MAXN];
  SAM() { last = tot = 1; }
  void extend(int c) {
    static int p, q, np, nq;
    p = last;
    last = ++tot;
    np = tot;
    len[np] = len[p] + 1;
    size[np] = 1;
    for (; p && !son[p][c]; p = fa[p]) son[p][c] = np;
    if (!p) {
      fa[np] = 1;
      return;
    }
    q = son[p][c];
    if (len[q] == len[p] + 1) {
      fa[np] = q;
      return;
    }
    nq = ++tot;
    memcpy(son[nq], son[q], sizeof(son[nq]));
    len[nq] = len[p] + 1;
    fa[nq] = fa[q];
    fa[q] = fa[np] = nq;
    for (; p && son[p][c] == q; p = fa[p]) son[p][c] = nq;
  }
  void dfs(int u) {
    for (int v : G[u]) dfs(v), size[u] += size[v];
  }
  void init() {
    for (int i = 2; i <= tot; i++) G[fa[i]].push_back(i);
    dfs(1);
  }
  void solve(char *s) {
    vector<int> vec;
    int n = strlen(s + 1), lcs = 0, res = 0;
    for (int i = n + 1; i < n * 2; i++) s[i] = s[i - n];
    for (int i = 1, u = 1; i < n * 2; i++) {
      int c = s[i] - 'a';
      if (son[u][c])
        u = son[u][c], lcs += 1;
      else {
        for (; u && !son[u][c]; u = fa[u])
          ;
        if (!u)
          u = 1, lcs = 0;
        else
          lcs = len[u] + 1, u = son[u][c];
      }
      if (lcs > n)
        while (len[fa[u]] >= n) u = fa[u], lcs = len[u];
      if (lcs >= n && !vis[u]) {
        vis[u] = 1;
        vec.push_back(u);
        res += size[u];
      }
    }
    for (int v : vec) vis[v] = 0;
    printf("%d\n", res);
  }
} sam;
int main() {
  scanf("%s%d", s + 1, &n);
  int len = strlen(s + 1);
  for (int i = 1; i <= len; i++) sam.extend(s[i] - 'a');
  sam.init();
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    sam.solve(s);
  }
  return 0;
}