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 SAM_SONN = 26;
const int SAM_N = 2e6 + 10;
struct node {
  int son[SAM_SONN];
  int len, fail, sum;
  int bz;
  void clear() {
    memset(son, 0, sizeof(son));
    len = fail = 0;
  }
} tri[SAM_N];
int lst, L;
void init() {
  while (L) tri[L--].clear();
  lst = L = 1;
}
int add(int last, int c) {
  static int v, u, up, up1;
  v = ++L;
  u = last;
  tri[v].len = tri[u].len + 1;
  for (; u && !tri[u].son[c]; u = tri[u].fail) tri[u].son[c] = v;
  if (!u)
    tri[v].fail = 1;
  else {
    up = tri[u].son[c];
    if (tri[up].len == tri[u].len + 1)
      tri[v].fail = up;
    else {
      up1 = ++L;
      tri[up1] = tri[up];
      tri[up1].len = tri[u].len + 1;
      tri[up1].sum = 0;
      tri[up].fail = tri[v].fail = up1;
      for (; u && tri[u].son[c] == up; u = tri[u].fail) tri[u].son[c] = up1;
    }
  }
  return lst = v;
}
vector<int> d;
int tmp[SAM_N];
void gettp() {
  int mxlen = 0;
  for (int i = 1; i <= L; i++) mxlen = max(tri[i].len, mxlen);
  for (int i = 0; i <= mxlen; i++) tmp[i] = 0;
  d.resize(L);
  for (int i = 1; i <= L; i++) tmp[tri[i].len]++;
  for (int i = mxlen - 1; i >= 0; i--) tmp[i] += tmp[i + 1];
  for (int i = 1; i <= L; i++) d[--tmp[tri[i].len]] = i;
}
const int N = 1e6 + 10;
char s[N];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  init();
  for (int i = 0; i < n; i++) tri[add(lst, s[i] - 'a')].sum++;
  gettp();
  for (int i = 0; i < L - 1; i++) tri[tri[d[i]].fail].sum += tri[d[i]].sum;
  int T;
  scanf("%d", &T);
  int tag = 0;
  while (T--) {
    scanf("%s", s);
    int n = strlen(s);
    ++tag;
    int len = 0;
    int x = 1;
    int ans = 0;
    for (int i = 0; i < n + n; i++) {
      char c = s[i % n] - 'a';
      while (x != 1 && !tri[x].son[c]) {
        x = tri[x].fail;
        len = tri[x].len;
      }
      if (!tri[x].son[c]) {
        continue;
      }
      x = tri[x].son[c];
      len++;
      while (tri[tri[x].fail].len >= n) {
        x = tri[x].fail;
        len = tri[x].len;
      }
      if (len >= n && tri[x].bz != tag) {
        tri[x].bz = tag;
        ans += tri[x].sum;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}