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 = 1000005;
struct node {
  int son[26], len, fail;
} tr[N * 2];
int sz = 1, lst = 1, id[N * 2], tot[N * 2], Right[N * 2];
void insert(int x) {
  int np = ++sz, p = lst;
  lst = np;
  tr[np].len = tr[p].len + 1;
  while (p && !tr[p].son[x]) tr[p].son[x] = np, p = tr[p].fail;
  if (!p)
    tr[np].fail = 1;
  else {
    int q = tr[p].son[x];
    if (tr[q].len == tr[p].len + 1)
      tr[np].fail = q;
    else {
      int nq = ++sz;
      tr[nq] = tr[q];
      tr[nq].len = tr[p].len + 1;
      tr[np].fail = tr[q].fail = nq;
      while (p && tr[p].son[x] == q) tr[p].son[x] = nq, p = tr[p].fail;
    }
  }
}
int n, Q;
void init() {
  for (int i = 1; i <= sz; i++) tot[tr[i].len]++;
  for (int i = 1; i <= n; i++) tot[i] += tot[i - 1];
  for (int i = 1; i <= sz; i++) id[tot[tr[i].len]--] = i;
  for (int i = sz; i; i--) {
    int x = id[i], fa = tr[x].fail;
    Right[fa] += Right[x];
  }
}
char s[N * 2];
int vis[N * 2];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) insert(s[i] - 'a');
  for (int i = 1, now = 1; i <= n; i++) {
    now = tr[now].son[s[i] - 'a'];
    Right[now]++;
  }
  init();
  scanf("%d", &Q);
  int sign = 0;
  while (Q--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (int i = 1; i < n; i++) s[n + i] = s[i];
    s[2 * n] = 0;
    long long ans = 0;
    ++sign;
    for (int i = 1, now = 1, len = 0; i < 2 * n; i++) {
      int j = s[i] - 'a';
      while (now && !tr[now].son[j]) now = tr[now].fail, len = tr[now].len;
      if (!now)
        now = 1, len = 0;
      else
        now = tr[now].son[j], len++;
      while (tr[now].fail && tr[tr[now].fail].len >= n)
        now = tr[now].fail, len = tr[now].len;
      if (len >= n) {
        if (vis[now] != sign) ans += Right[now];
        vis[now] = sign;
      }
    }
    cout << ans << "\n";
  }
}