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 N = 2e6 + 5;
int link[N], nxt[N][26], len[N], in[N], cnt = 1, las = 1;
char s[N];
map<int, bool> vis;
long long num[N];
void insert(int c) {
  int cur = ++cnt, p = las;
  len[cur] = len[p] + 1;
  las = cur;
  for (; p && nxt[p][c] == 0; p = link[p]) nxt[p][c] = cur;
  if (!p)
    link[cur] = 1;
  else {
    int q = nxt[p][c];
    if (len[p] == len[q] - 1)
      link[cur] = q;
    else {
      int clone = ++cnt;
      len[clone] = len[p] + 1;
      link[clone] = link[q];
      link[q] = link[cur] = clone;
      memcpy(nxt[clone], nxt[q], sizeof(nxt[q]));
      for (; nxt[p][c] == q; p = link[p]) nxt[p][c] = clone;
    }
  }
  num[cur] = 1;
}
void topu() {
  queue<int> q;
  for (int i = 1; i <= cnt; i++) in[link[i]]++;
  for (int i = 1; i <= cnt; i++)
    if (!in[i]) q.push(i);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    int u = link[now];
    if (--in[u] == 0) q.push(u);
    num[u] += num[now];
  }
}
int main() {
  scanf("%s", s + 1);
  for (int i = 1, l = strlen(s + 1); i <= l; i++) insert(s[i] - 'a');
  topu();
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s + 1);
    int l = strlen(s + 1);
    for (int i = 1; i <= l; i++) s[i + l] = s[i];
    l <<= 1;
    vis.clear();
    long long ans = 0;
    for (int i = 1, match = 0, now = 1, last = s[1] - 'a'; i < l; i++) {
      int c = s[i] - 'a';
      last = c;
      int next = nxt[now][c];
      if (!next) {
        while (now && !next) now = link[now], next = nxt[now][c];
        if (!now)
          match = 0, now = 1;
        else
          match = len[now] + 1, now = next;
      } else {
        match++;
        now = next;
      }
      if (match >= l / 2) {
        while (now && len[link[now]] >= l / 2) now = link[now];
        if (vis.count(now))
          continue;
        else
          vis[now] = true;
        ans += num[now];
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}