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("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAX = 1e6 + 5;
const long long MOD = 1000000007;
struct state {
  int len, link, cnt;
  int nx[26];
} st[MAX << 1];
int id, last, cur;
vector<int> v[MAX];
inline void sa_init() {
  st[0].link = -1;
  memset(st[0].nx, 0, sizeof st[0].nx);
  id = last = st[0].cnt = 0;
}
inline void sa_extend(int c) {
  int clone;
  st[last].nx[c] = cur = ++id;
  st[cur].len = st[last].len + 1;
  v[st[cur].len].push_back(cur);
  st[cur].cnt = 1;
  int p = last;
  while (1) {
    if ((p = st[p].link) == -1) {
      st[cur].link = 0;
      break;
    }
    if (st[p].nx[c]) {
      int q = st[p].nx[c];
      if (st[p].len + 1 == st[q].len)
        st[cur].link = q;
      else {
        clone = ++id;
        st[clone] = st[q];
        st[clone].cnt = 0;
        st[clone].len = st[p].len + 1;
        v[st[clone].len].push_back(clone);
        st[q].link = st[cur].link = clone;
        while (p != -1 && st[p].nx[c] == q) {
          st[p].nx[c] = clone;
          p = st[p].link;
        }
      }
      break;
    } else
      st[p].nx[c] = cur;
  }
  last = cur;
  return;
}
inline int lcs(string &s, string &t) {
  sa_init();
  for (char c : s) sa_extend(c - 'a');
  int best = 0, len = 0;
  cur = 0;
  for (char c : t) {
    c -= 'a';
    while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len;
    if (st[cur].nx[c]) {
      cur = st[cur].nx[c];
      best = max(best, ++len);
    }
  }
  return best;
}
bool vis[MAX << 1];
vector<int> del;
inline int solve(string &s) {
  int n = s.size(), ans = 0, len = 0;
  del.clear();
  s += s;
  cur = 0;
  for (char c : s) {
    c -= 'a';
    while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len;
    if (st[cur].nx[c]) {
      cur = st[cur].nx[c], ++len;
      if (len == n) {
        if (!vis[cur]) ans += st[cur].cnt, vis[cur] = 1, del.push_back(cur);
        --len;
        if (len == st[st[cur].link].len) cur = st[cur].link;
      }
    }
  }
  for (int i : del) vis[i] = 0;
  return ans;
}
string s;
int q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  sa_init();
  cin >> s;
  for (char c : s) sa_extend(c - 'a');
  for (int i = s.size(); i >= 1; --i)
    for (int j : v[i]) st[st[j].link].cnt += st[j].cnt;
  cin >> q;
  while (q--) {
    cin >> s;
    cout << solve(s) << '\n';
  }
  return 0;
}