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 = 1e6 + 100;
const int Alpha = 27;
struct State {
  int visited;
  int Link, Len;
  int Next[Alpha];
  State() {
    visited = 0;
    Link = Len = 0;
    memset(Next, -1, sizeof Next);
  }
};
int Dp[2 * N];
class SuffixAutmaton {
 public:
  int Sz, Last;
  vector<State> st;
  vector<bool> Terminal;
  void init(int n) {
    st.clear();
    st.resize(2 * n);
    Terminal.clear();
    Terminal.resize(2 * n);
    st[0].Len = 0;
    st[0].Link = -1;
    Sz = 1;
    Last = 0;
  }
  void Add(char ch) {
    int c = ch - 'a';
    int Cur = Sz++;
    st[Cur].Len = st[Last].Len + 1;
    int p = Last;
    while (p != -1 && st[p].Next[c] == -1) {
      st[p].Next[c] = Cur;
      p = st[p].Link;
    }
    if (p == -1) {
      st[Cur].Link = 0;
    } else {
      int q = st[p].Next[c];
      if (st[p].Len + 1 == st[q].Len) {
        st[Cur].Link = q;
      } else {
        int Clone = Sz++;
        st[Clone].Len = st[p].Len + 1;
        st[Clone].Link = st[q].Link;
        for (int i = 0; i < Alpha; i++) st[Clone].Next[i] = st[q].Next[i];
        while (p != -1 && st[p].Next[c] == q) {
          st[p].Next[c] = Clone;
          p = st[p].Link;
        }
        st[q].Link = st[Cur].Link = Clone;
      }
    }
    Last = Cur;
  }
  void GetTerminal() {
    int p = Last;
    while (p > 0) {
      Terminal[p] = 1;
      p = st[p].Link;
    }
  }
  void Build(string& s) {
    init(s.size());
    for (auto i : s) Add(i);
    GetTerminal();
  }
  void getPaths(int u) {
    if (Dp[u]) return;
    Dp[u] = Terminal[u];
    for (int i = 0; i < Alpha; i++)
      if (st[u].Next[i] + 1) {
        getPaths(st[u].Next[i]);
        Dp[u] += Dp[st[u].Next[i]];
      }
  }
  int Solve(string& s, int test) {
    int u = 0;
    int Res = 0;
    int length = s.size();
    s += s;
    int j = 0;
    for (int i = 0; i < length; i++) {
      while (j < i + length) {
        if (st[u].Next[s[j] - 'a'] == -1) break;
        u = st[u].Next[s[j++] - 'a'];
      }
      if (j - i == length && st[u].visited != test) {
        Res += Dp[u];
        st[u].visited = test;
      }
      int newLength = j - i - 1;
      if (u && st[st[u].Link].Len >= newLength) u = st[u].Link;
    }
    return Res;
  }
} SA;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  SA.Build(s);
  SA.getPaths(0);
  int T;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    string q;
    cin >> q;
    cout << SA.Solve(q, i) << '\n';
  }
  return 0;
}