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 + 6;
const int M = N + N;
char s[N];
int sufLink[M];
int to[M][26];
int len[M];
bool terminal[M];
int n;
int size, last;
void append(int c) {
  int cur = size++;
  len[cur] = len[last] + 1;
  int p = last;
  for (; ~p && to[p][c] == 0; p = sufLink[p]) to[p][c] = cur;
  if (p == -1) {
    sufLink[cur] = 0;
  } else {
    int q = to[p][c];
    if (len[p] + 1 == len[q]) {
      sufLink[cur] = q;
    } else {
      int clone = size++;
      sufLink[clone] = sufLink[q];
      copy(to[q], to[q] + 26, to[clone]);
      len[clone] = len[p] + 1;
      for (; ~p && to[p][c] == q; p = sufLink[p]) to[p][c] = clone;
      sufLink[cur] = clone;
      sufLink[q] = clone;
    }
  }
  last = cur;
}
void buildSAM() {
  size = 1;
  last = 0;
  sufLink[0] = -1;
  n = strlen(s);
  for (int i = 0; i < n; ++i) append(s[i] - 'a');
  for (int i = last; i; i = sufLink[i]) terminal[i] = true;
}
int memo[M];
int dp(int u) {
  if (memo[u] != -1) return memo[u];
  memo[u] = terminal[u];
  for (int i = 0; i < 26; ++i) {
    int v = to[u][i];
    if (v) memo[u] += dp(v);
  }
  return memo[u];
}
int query(string s) {
  int n = s.size();
  s += s;
  set<int> was;
  int match = 0, node = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    while (match < n && to[node][s[i + match] - 'a'] != 0) {
      node = to[node][s[i + match] - 'a'];
      ++match;
    }
    if (match == n && !was.count(node)) {
      ans += dp(node);
      was.insert(node);
    }
    if (match > 0) --match;
    if (~node && len[sufLink[node]] == match) node = sufLink[node];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  buildSAM();
  memset(memo, -1, sizeof memo);
  int q;
  cin >> q;
  while (q--) {
    cin >> s;
    cout << query(s) << '\n';
  }
  return 0;
}