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>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
const int INF = 2139062143;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 2e6 + 7;
const int M = 26 + 1;
int n, L, E, ans, cnt, lst, sz[N], fa[N], len[N], vis[N], head[N], ch[N][M];
char s[N], st[N];
struct EDGE {
  int to, nxt;
} edge[N];
inline void addedge(int u, int v) {
  edge[++E].to = v;
  edge[E].nxt = head[u];
  head[u] = E;
}
inline void Extend(int c) {
  int p = lst, q = ++cnt;
  lst = q;
  len[q] = len[p] + 1;
  sz[q] = 1;
  while (p && !ch[p][c]) {
    ch[p][c] = q;
    p = fa[p];
  }
  if (p == 0) {
    fa[q] = 1;
  } else {
    int x = ch[p][c];
    if (len[p] + 1 == len[x]) {
      fa[q] = x;
    } else {
      int y = ++cnt;
      fa[y] = fa[x];
      fa[x] = fa[q] = y;
      len[y] = len[p] + 1;
      memcpy(ch[y], ch[x], sizeof(ch[x]));
      while (p && ch[p][c] == x) {
        ch[p][c] = y;
        p = fa[p];
      }
    }
  }
}
inline void dfs(int u) {
  for (int i = head[u]; i; i = edge[i].nxt) {
    int v = edge[i].to;
    dfs(v);
    sz[u] += sz[v];
  }
}
int main() {
  scanf("%s", s);
  lst = cnt = 1;
  for (int i = 0, l = strlen(s); i < l; i++) Extend(s[i] - 'a' + 1);
  read(n);
  for (int i = 2; i <= cnt; i++) addedge(fa[i], i);
  dfs(1);
  for (int i = 1; i <= n; i++) {
    scanf("%s", st);
    int p = 1, length = 0, l = strlen(st), ans = 0;
    for (int i = 0; i < l - 1; i++) st[i + l] = st[i];
    int n_l = 2 * l - 1;
    for (int j = 0; j < n_l; j++) {
      int c = st[j] - 'a' + 1;
      if (ch[p][c])
        p = ch[p][c], length++;
      else {
        while (p && !ch[p][c]) p = fa[p];
        if (p)
          length = len[p] + 1, p = ch[p][c];
        else
          p = 1, length = 0;
      }
      if (length == l) {
        if (vis[p] < i) ans += sz[p], vis[p] = i;
        if (len[fa[p]] == length - 1) p = fa[p];
        length--;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}