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 = 2000100;
int go[N][26], par[N], val[N], endpos[N];
int root = 1, last = 1, tot = 1;
inline void newn(int &x, int v, int *g, int f) {
  x = ++tot, val[x] = v, par[x] = f;
  if (g)
    for (int i = 0, nn = int(26); i < nn; ++i) go[x][i] = g[i];
}
inline void insert(int x) {
  int np;
  newn(np, val[last] + 1, NULL, 0);
  endpos[np] = 1;
  int p = last;
  last = np;
  while (p && go[p][x] == 0) go[p][x] = np, p = par[p];
  if (!p)
    par[np] = root;
  else {
    int q = go[p][x];
    if (val[q] == val[p] + 1)
      par[np] = q;
    else {
      int nq;
      newn(nq, val[p] + 1, go[q], par[q]);
      while (p && go[p][x] == q) go[p][x] = nq, p = par[p];
      par[q] = par[np] = nq;
    }
  }
}
inline void query(string &s, int len) {
  int u = root, l = 0, x, ans = 0;
  static bitset<N> vis;
  vis.reset();
  for (int i = 0, nn = int(s.length()); i < nn; ++i) {
    x = s[i] - 'a';
    while (u && !go[u][x]) u = par[u], l = val[u];
    if (!u) u = root, l = 0;
    if (go[u][x]) u = go[u][x], ++l;
    while (u && val[par[u]] >= len) u = par[u], l = val[u];
    if (l >= len && !vis[u]) vis.set(u), ans += endpos[u];
  }
  printf("%d\n", ans);
}
int main() {
  ios ::sync_with_stdio(false);
  string s;
  cin >> s;
  for (int i = 0, nn = int(s.length()); i < nn; ++i) insert(s[i] - 'a');
  static int ss[N / 2], ord[N];
  for (int i = 1, nn = int(tot); i <= nn; ++i) ++ss[val[i]];
  for (int i = 1, nn = int(val[last]); i <= nn; ++i) ss[i] += ss[i - 1];
  for (int i = 1, nn = int(tot); i <= nn; ++i) ord[ss[val[i]]--] = i;
  for (int i = tot, nn = int(1); i >= nn; --i) {
    int x = ord[i];
    endpos[par[x]] += endpos[x];
  }
  int n;
  cin >> n;
  while (n--) {
    cin >> s;
    int l = s.length();
    for (int i = 0, nn = int(l - 1); i < nn; ++i) s += s[i];
    query(s, l);
  }
  return 0;
}