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 maxn = 2e6 + 10;
struct node {
  int Next[26], len, fa;
} Tree[maxn];
int n, m, N, last = 1, tot = 1, f[maxn], Begin[maxn], Next[maxn], To[maxn], e;
bool vis[maxn];
char s[maxn];
vector<int> Rub;
inline void add(int u, int v) {
  To[++e] = v;
  Next[e] = Begin[u];
  Begin[u] = e;
}
inline void Extand(int c) {
  int cur = ++tot;
  f[cur] = 1;
  Tree[cur].len = Tree[last].len + 1;
  int p = last;
  last = cur;
  while (p && !Tree[p].Next[c]) {
    Tree[p].Next[c] = cur;
    p = Tree[p].fa;
  }
  if (!p) {
    Tree[cur].fa = 1;
    return;
  }
  int q = Tree[p].Next[c];
  if (Tree[p].len + 1 == Tree[q].len)
    Tree[cur].fa = q;
  else {
    int clone = ++tot;
    Tree[clone] = Tree[q];
    Tree[clone].len = Tree[p].len + 1;
    while (p && Tree[p].Next[c] == q) {
      Tree[p].Next[c] = clone;
      p = Tree[p].fa;
    }
    Tree[cur].fa = Tree[q].fa = clone;
  }
}
inline void DFS(int u) {
  for (int i = Begin[u]; i; i = Next[i]) {
    int v = To[i];
    DFS(v);
    f[u] += f[v];
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) Extand(s[i] - 'a');
  for (int i = (2), _end_ = (tot); i <= _end_; ++i) add(Tree[i].fa, i);
  DFS(1);
  scanf("%d", &m);
  while (m--) {
    scanf("%s", s + 1);
    N = strlen(s + 1);
    for (int i = (1), _end_ = (N); i <= _end_; ++i) s[i + N] = s[i];
    N += N;
    int ans = 0, p = 1, len = 0;
    for (int i = (1), _end_ = (N - 1); i <= _end_; ++i) {
      int c = s[i] - 'a';
      while (p != 1 && !Tree[p].Next[c]) {
        p = Tree[p].fa;
        len = Tree[p].len;
      }
      if (Tree[p].Next[c]) {
        p = Tree[p].Next[c];
        ++len;
      }
      while (p != 1 && Tree[Tree[p].fa].len >= N / 2) {
        p = Tree[p].fa;
        len = Tree[p].len;
      }
      if (len >= N / 2 && !vis[p]) {
        ans += f[p];
        vis[p] = true;
        Rub.push_back(p);
      }
    }
    for (auto i : Rub) vis[i] = false;
    Rub.clear();
    printf("%d\n", ans);
  }
  return 0;
}