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>
#pragma GCC optimize("O3")
using namespace std;
string s;
int q;
void read() { cin >> s >> q; }
struct node {
  int link, cnt, len;
  map<int, int> next;
};
const int maxn = 2e6 + 3;
int idx, last;
node sa[maxn * 2];
void init_sa() {
  idx = last = 0;
  sa[0] = {-1, 0, 0, {}};
}
void extend_sa(char ch) {
  int curr = ++idx;
  sa[curr] = {-1, 1, sa[last].len + 1, {}};
  int p = last;
  while (p != -1 && !sa[p].next.count(ch - 'a'))
    sa[p].next[ch - 'a'] = curr, p = sa[p].link;
  if (p == -1)
    sa[curr].link = 0;
  else {
    int q = sa[p].next[ch - 'a'];
    if (sa[q].len == sa[p].len + 1)
      sa[curr].link = q;
    else {
      sa[++idx] = {sa[q].link, 0, sa[p].len + 1, sa[q].next};
      sa[q].link = sa[curr].link = idx;
      while (p != -1 && sa[p].next[ch - 'a'] == q)
        sa[p].next[ch - 'a'] = idx, p = sa[p].link;
    }
  }
  last = curr;
}
vector<int> adj[maxn * 2];
void pre_dfs(int ver) {
  for (auto i : adj[ver]) {
    pre_dfs(i);
    sa[ver].cnt += sa[i].cnt;
  }
}
void extend(int &pos, int &len, char ch) {
  while (pos != -1 && !sa[pos].next.count(ch - 'a')) {
    pos = sa[pos].link;
    len = sa[pos].len;
  }
  if (pos == -1)
    pos = 0, len = 0;
  else {
    len++;
    pos = sa[pos].next[ch - 'a'];
  }
}
bool used[maxn];
vector<int> v;
void solve() {
  init_sa();
  for (auto i : s) extend_sa(i);
  for (int i = 0; i <= idx; i++)
    if (sa[i].link != -1) adj[sa[i].link].push_back(i);
  pre_dfs(0);
  while (q--) {
    string t;
    cin >> t;
    long long ans = 0;
    int pos = 0, len = 0;
    for (auto i : t) {
      extend(pos, len, i);
      if (len >= (int)t.size()) {
        while (sa[pos].link != 0 && sa[sa[pos].link].len >= (int)t.size())
          pos = sa[pos].link;
        if (!used[pos]) {
          v.push_back(pos);
          used[pos] = true;
        }
      }
    }
    for (auto i : t) {
      extend(pos, len, i);
      if (len >= (int)t.size()) {
        while (sa[pos].link != 0 && sa[sa[pos].link].len >= (int)t.size())
          pos = sa[pos].link;
        if (!used[pos]) {
          v.push_back(pos);
          used[pos] = true;
        }
      }
    }
    for (auto i : v) ans += sa[i].cnt, used[i] = false;
    v.clear();
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}