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;
int T, n, m, las = 1, ndnum = 1, ans;
char s[maxn];
struct node {
  int ch[26], len, fa;
} d[maxn << 1];
int siz[maxn << 1], vis[maxn << 1], timer;
int head[maxn << 1], tot;
struct edge {
  int nxt, to;
} e[maxn << 1];
void Addedge(int x, int y) {
  e[++tot] = (edge){head[x], y};
  head[x] = tot;
}
void Insert(int x) {
  int p = las, np = las = ++ndnum;
  siz[np] = 1;
  d[np].len = d[p].len + 1;
  while (p && !d[p].ch[x]) {
    d[p].ch[x] = np;
    p = d[p].fa;
  }
  if (!p) {
    d[np].fa = 1;
  } else {
    int q = d[p].ch[x];
    if (d[q].len == d[p].len + 1) {
      d[np].fa = q;
    } else {
      int nq = ++ndnum;
      d[nq] = d[q];
      d[nq].len = d[p].len + 1;
      d[q].fa = d[np].fa = nq;
      while (p && d[p].ch[x] == q) {
        d[p].ch[x] = nq;
        p = d[p].fa;
      }
    }
  }
}
void dfs(int x) {
  int id;
  for (int i = head[x]; i; i = e[i].nxt) {
    id = e[i].to;
    dfs(id);
    siz[x] += siz[id];
  }
}
void go(int &x, int y, int &len) {
  if (d[x].ch[y]) {
    ++len;
    x = d[x].ch[y];
  } else {
    while (x && !d[x].ch[y]) x = d[x].fa;
    if (!x) {
      x = 1;
      len = 0;
    } else {
      len = d[x].len + 1;
      x = d[x].ch[y];
    }
  }
}
void del(int &x, int &len) {
  if (len != m) return;
  --len;
  if (len == d[d[x].fa].len) x = d[x].fa;
}
void work(int x, int y) {
  if (y < m || vis[x] == timer) return;
  ans += siz[x];
  vis[x] = timer;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) Insert(s[i] - 'a');
  for (int i = 2; i <= ndnum; ++i) Addedge(d[i].fa, i);
  dfs(1);
  scanf("%d", &T);
  int now, len;
  while (T--) {
    scanf("%s", s + 1);
    m = strlen(s + 1);
    now = 1;
    len = 0;
    for (int i = 1; i <= m; ++i) go(now, s[i] - 'a', len);
    ++timer;
    ans = 0;
    work(now, len);
    for (int i = 1; i < m; ++i) {
      del(now, len);
      go(now, s[i] - 'a', len);
      work(now, len);
    }
    printf("%d\n", ans);
  }
  return 0;
}