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 P(29), N(1000010);
int tail, t, n, m, p, len, h;
set<int> ha;
int g[2 * N][26];
vector<int> link[2 * N];
string s;
int b[N];
int cnt[2 * N], fa[2 * N], l[2 * N];
void add(int c) {
  int p = tail, np = ++t;
  ++cnt[np];
  l[np] = l[p] + 1;
  for (; p && !g[p][c]; p = fa[p]) g[p][c] = np;
  tail = np;
  if (!p)
    fa[np] = 1;
  else if (l[p] + 1 == l[g[p][c]])
    fa[np] = g[p][c];
  else {
    int q = g[p][c], r = ++t;
    memcpy(g[r], g[q], sizeof(g[q]));
    fa[r] = fa[q];
    l[r] = l[p] + 1;
    fa[q] = fa[np] = r;
    for (; p && g[p][c] == q; p = fa[p]) g[p][c] = r;
  }
}
void dfs(int x) {
  for (int i = int(0); i < int(link[x].size()); ++i) {
    dfs(link[x][i]);
    cnt[x] += cnt[link[x][i]];
  }
}
int main() {
  b[0] = 1;
  for (int i = int(1); i < int(N); ++i) b[i] = b[i - 1] * P;
  cin >> s;
  n = s.size();
  tail = t = 1;
  for (int i = int(0); i < int(n); ++i) add(s[i] - 'a');
  for (int i = int(2); i < int(t + 1); ++i) link[fa[i]].push_back(i);
  dfs(1);
  for (cin >> m; m; --m) {
    cin >> s;
    n = s.size();
    s = s + s;
    p = 0;
    len = 0;
    h = 0;
    long long ans = 0;
    ha.clear();
    for (int i = int(0); i < int(2 * n - 1); ++i) {
      if (p == 0) p = 1;
      for (; p != 1 && !g[p][s[i] - 'a']; p = fa[p])
        ;
      len = min(len, l[p]);
      p = g[p][s[i] - 'a'];
      if (p) ++len;
      h = h * P + s[i] - 'a' + 1;
      if (i >= n) h -= (s[i - n] - 'a' + 1) * b[n];
      if (len == n) {
        if (!ha.count(h)) {
          ha.insert(h);
          ans += cnt[p];
        }
        if (len == l[fa[p]] + 1) p = fa[p];
        --len;
      }
    }
    cout << ans << endl;
  }
  return 0;
}