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;
inline bool cmp(const pair<int, int> &p, const pair<int, int> &q) {
  return (p.first == q.first) ? p.second > q.second : p.first > q.first;
}
struct state {
  int len, link, cnt, num;
  int next[26];
};
state st[1000002 * 2];
int last;
int sz, n;
char str1[1000002];
void ini_sa() {
  sz = 0;
  st[0].len = 0;
  st[0].link = -1;
  for (int i = 0; i < 26; i++) st[0].next[i] = -1;
  ++sz;
}
void sa_insert(int c) {
  int cur = sz++;
  st[cur].len = st[last].len + 1;
  st[cur].cnt = 1;
  for (int i = 0; i < 26; i++) st[cur].next[i] = -1;
  int p;
  for (p = last; (p != -1) && (st[p].next[c] == -1); p = st[p].link)
    st[p].next[c] = cur;
  if (p == -1)
    st[cur].link = 0;
  else {
    int q = st[p].next[c];
    if (st[q].len == (st[p].len + 1)) {
      st[cur].link = q;
    } else {
      int clone = sz++;
      st[clone].len = st[p].len + 1;
      st[clone].cnt = 0;
      memcpy(st[clone].next, st[q].next, sizeof st[clone].next);
      st[clone].link = st[q].link;
      int temp = clone;
      for (; (p != -1) && (st[p].next[c] == q); p = st[p].link) {
        st[p].next[c] = clone;
      }
      st[q].link = st[cur].link = clone;
    }
  }
  last = cur;
}
int b[1000002 << 1];
pair<int, int> A[1000002 << 1];
int main() {
  ini_sa();
  int p;
  scanf("%s", str1);
  n = strlen(str1);
  int L = n;
  for (int i = 0; i < n; i++) {
    sa_insert(str1[i] - 'a');
  }
  for (int i = 0; i < sz; i++) A[i] = make_pair(st[i].len, i);
  sort(A, A + sz, cmp);
  for (int i = 0; i < sz; i++) b[i] = A[i].second;
  for (int i = 0; i < sz - 1; i++)
    if (b[i]) {
      st[st[b[i]].link].cnt += st[b[i]].cnt;
    }
  int q;
  scanf("%d", &q);
  long long track = 0ll, tend = 0ll;
  for (int kk = 0; kk < 26; kk++)
    if (st[0].next[kk] != -1) tend |= (1ll << kk);
  int vis[sz];
  memset(vis, -1, sizeof vis);
  while (q--) {
    scanf("%s", str1);
    L = strlen(str1);
    long long ans = 0ll;
    track = 0ll;
    long long t2end = 0ll;
    for (int i = 0; i < L; i++) t2end |= (1ll << (int)(str1[i] - 'a'));
    if (t2end > tend) {
      printf("0\n");
      continue;
    }
    int v = 0, j = 0, len = 0, mm = 0;
    L += L;
    for (int i = 0; i < L - 1; i++) {
      while (v && (st[v].next[str1[i % (L / 2)] - 'a'] == -1)) {
        v = st[v].link;
        len = st[v].len;
      }
      if (st[v].next[str1[i % (L / 2)] - 'a'] != -1) {
        v = st[v].next[str1[i % (L / 2)] - 'a'];
        len++;
      }
      if (len >= (L >> 1)) {
        while (v && st[st[v].link].len >= (L >> 1)) {
          v = st[v].link;
          len = st[v].len;
        }
        if (vis[v] != q) {
          vis[v] = q;
          ans += st[v].cnt;
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}