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 maxn = 1000005 << 1, sigma = 26;
int last, sz, link[maxn], len[maxn], nxt[maxn][sigma], cnt[maxn];
void init() {
  for (int i = 0; i < sz; i++) memset(nxt[i], 0, sizeof nxt[i]), cnt[i] = 0;
  len[0] = last = 0;
  link[0] = -1;
  sz = 1;
}
void insert(int c) {
  int cur = sz++, p = last;
  len[cur] = len[last] + 1;
  cnt[cur] = 1;
  while (p != -1 && !nxt[p][c]) {
    nxt[p][c] = cur;
    p = link[p];
  }
  if (p == -1)
    link[cur] = 0;
  else {
    int q = nxt[p][c];
    if (len[p] + 1 == len[q])
      link[cur] = q;
    else {
      int clone = sz++;
      memcpy(nxt[clone], nxt[q], sizeof nxt[q]);
      len[clone] = len[p] + 1;
      link[clone] = link[q];
      link[q] = link[cur] = clone;
      while (p != -1 && nxt[p][c] == q) {
        nxt[p][c] = clone;
        p = link[p];
      }
    }
  }
  last = cur;
}
int fail[maxn];
void FailureFunction(string& pattern) {
  fail[0] = 0;
  for (int i = 1; i < pattern.size(); i++) {
    fail[i] = fail[i - 1];
    while (fail[i] > 0 && pattern[fail[i]] != pattern[i])
      fail[i] = fail[fail[i] - 1];
    if (pattern[fail[i]] == pattern[i]) fail[i]++;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  init();
  for (int i = 0; i < s.size(); i++) insert(s[i] - 'a');
  vector<pair<int, int> > v;
  for (int i = 1; i < sz; i++) v.emplace_back(make_pair(len[i], i));
  sort(v.begin(), v.end(), greater<pair<int, int> >());
  for (auto it : v) cnt[link[it.second]] += cnt[it.second];
  int T;
  cin >> T;
  while (T--) {
    cin >> s;
    int ans = 0, n = s.size();
    ;
    FailureFunction(s);
    int repeat;
    if (n % (n - fail[n - 1]))
      repeat = n;
    else
      repeat = n - fail[n - 1];
    int now = 0, l = 0;
    for (int i = 0; i < n; i++) {
      int c = s[i] - 'a';
      while (now != -1 && !nxt[now][c]) now = link[now], l = len[now];
      if (now == -1)
        now = 0;
      else
        now = nxt[now][c], l++;
    }
    if (l == n) ans += cnt[now];
    for (int i = 0; i < repeat - 1; i++) {
      if (l == n) {
        l--;
        if (l <= len[link[now]]) now = link[now], l = len[now];
      }
      int c = s[i] - 'a';
      while (now != -1 && !nxt[now][c]) now = link[now], l = len[now];
      if (now == -1)
        now = 0;
      else
        now = nxt[now][c], l++;
      if (l == n) ans += cnt[now];
    }
    cout << ans << '\n';
  }
}