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 <typename T>
inline void read(T &t) {
  t = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    t = (t << 3) + (t << 1) + c - '0';
    c = getchar();
  }
  t *= f;
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int n, node = 1, lst = 1;
int ch[2000005][26], fa[2000005], len[2000005];
int cnt[2000005], las[2000005];
char s[2000005];
struct edge {
  int v, nxt;
} e[2000005];
int top = 1;
int head[2000005];
void Add_Edge(int u, int v) {
  e[++top] = edge{v, head[u]};
  head[u] = top;
}
void Insert(int c) {
  int f = lst, q = lst = ++node;
  len[q] = len[f] + 1;
  cnt[q]++;
  while (f && !ch[f][c]) ch[f][c] = q, f = fa[f];
  if (f == 0)
    fa[q] = 1;
  else {
    int x = ch[f][c];
    if (len[x] == len[f] + 1)
      fa[q] = x;
    else {
      int p = ++node;
      len[p] = len[f] + 1;
      fa[p] = fa[x];
      fa[x] = fa[q] = p;
      memcpy(ch[p], ch[x], sizeof(ch[x]));
      while (f && ch[f][c] == x) ch[f][c] = p, f = fa[f];
    }
  }
}
void dfs(int u) {
  for (register int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    dfs(v);
    cnt[u] += cnt[v];
  }
}
void solve() {
  for (register int i = 2; i <= node; ++i) Add_Edge(fa[i], i);
  dfs(1);
}
int x, l, m, ans, tim;
void calc() {
  if (l == m && las[x] < tim) {
    ans += cnt[x];
    las[x] = tim;
  }
}
void del() {
  if (l > m && --l == len[fa[x]]) x = fa[x];
}
void Extend(int c) {
  while (x && !ch[x][c]) l = len[x = fa[x]];
  if (ch[x][c]) {
    ++l;
    x = ch[x][c];
  }
}
signed main() {
  int minlen = 0x7f7f7f7f;
  scanf("%s", s + 1);
  for (register int i = 1; s[i]; ++i) Insert(s[i] - 'a');
  solve();
  read(n);
  for (tim = 1; tim <= n; ++tim) {
    scanf("%s", s + 1);
    x = 1, l = 0, ans = 0, m = strlen(s + 1);
    for (register int i = 1; i <= m; ++i) Extend(s[i] - 'a');
    calc();
    for (register int i = 1; i < m; ++i) Extend(s[i] - 'a'), del(), calc();
    write(ans), putchar('\n');
  }
  return 0;
}