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;
struct SAM {
  int trans[26], len, fa;
} sam[2000005];
int tot, root, tail;
char s[2000005], ch;
void add(int ch, int len) {
  int p = tail, np = ++tot, q, r;
  sam[np].len = len;
  for (; p && !sam[p].trans[ch]; p = sam[p].fa) sam[p].trans[ch] = np;
  tail = np;
  if (!p)
    sam[np].fa = root;
  else if (sam[sam[p].trans[ch]].len == sam[p].len + 1)
    sam[np].fa = sam[p].trans[ch];
  else {
    q = sam[p].trans[ch];
    r = ++tot;
    sam[r] = sam[q];
    sam[r].len = sam[p].len + 1;
    sam[q].fa = sam[np].fa = r;
    for (; p && sam[p].trans[ch] == q; p = sam[p].fa) sam[p].trans[ch] = r;
  }
}
int T, l, i, j, k;
int tmp, cnt[2000005], sum[2000005], id[2000005];
int use[2000005];
long long ans;
int main() {
  root = tail = tot = 1;
  scanf("%s", s + 1);
  l = strlen(s + 1);
  for (i = 1; i <= l; ++i) add(s[i] - 'a', i);
  k = root;
  for (i = 1; i <= l; ++i) cnt[k = sam[k].trans[s[i] - 'a']] = 1;
  for (i = 2; i <= tot; ++i) ++sum[sam[i].len];
  for (i = l; i >= 1; --i) sum[i] += sum[i + 1];
  for (i = 2; i <= tot; ++i) id[sum[sam[i].len]--] = i;
  for (i = 1; i < tot; ++i) cnt[sam[id[i]].fa] += cnt[id[i]];
  scanf("%d", &T);
  for (; T; --T) {
    scanf("%s", s + 1);
    l = strlen(s + 1);
    for (i = 1; i <= l; ++i) s[i + l] = s[i];
    l += l;
    k = root;
    ans = tmp = 0;
    for (i = 1; i < l; ++i) {
      ch = s[i] - 'a';
      if (sam[k].trans[ch])
        ++tmp, k = sam[k].trans[ch];
      else {
        for (; k && !sam[k].trans[ch]; k = sam[k].fa)
          ;
        if (!k)
          tmp = 0, k = root;
        else {
          tmp = sam[k].len + 1;
          k = sam[k].trans[ch];
        }
      }
      if (tmp >= l / 2) {
        for (; sam[sam[k].fa].len >= l / 2; k = sam[k].fa)
          ;
        if (sam[k].len < tmp) tmp = sam[k].len;
        if (use[k] != T) ans += cnt[k], use[k] = T;
      }
    }
    printf("%I64d\n", ans);
  }
}