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;
struct Automaton {
  vector<int> len, suf;
  vector<map<char, int> > go;
  vector<bool> u;
  vector<long long> dp;
  vector<int> last;
  int p, sz;
  void clear() {
    go.clear();
    len.clear();
    suf.clear();
  }
  void build(string s) {
    int n = s.length() * 2 + 1;
    len.assign(n, 0);
    suf.assign(n, -1);
    go.resize(n);
    u.assign(n, 0);
    dp.assign(n, 0);
    last.assign(n, 0);
    for (int i = 0; i < n; i++) go[i].clear();
    p = 0;
    sz = 1;
    for (int i = 0; i < s.length(); i++) add(s[i]);
  }
  void add(char c) {
    int v = sz++;
    len[v] = len[p] + 1;
    for (; p >= 0 && !go[p].count(c); p = suf[p]) go[p][c] = v;
    if (p < 0) {
      suf[v] = 0;
    } else {
      int to = go[p][c];
      if (len[to] == len[p] + 1) {
        suf[v] = to;
      } else {
        int cl = sz++;
        go[cl] = go[to];
        len[cl] = len[p] + 1;
        suf[cl] = suf[to];
        for (; p >= 0 && go[p][c] == to; p = suf[p]) go[p][c] = cl;
        suf[to] = suf[v] = cl;
      }
    }
    p = v;
  }
  void dfs(int v) {
    if (u[v]) return;
    u[v] = true;
    if (go[v].count('$')) dp[v] = 1;
    for (auto x : go[v]) {
      dfs(x.second);
      dp[v] += dp[x.second];
    }
  }
  long long solve(string q, int id) {
    q = q + q;
    int l = 0;
    int v = 0;
    int ql = q.length();
    int want = ql / 2;
    long long res = 0;
    for (int i = 0; i < ql; i++) {
      while (v >= 0 && !go[v].count(q[i])) {
        v = suf[v];
        if (v >= 0) l = len[v];
      }
      if (v < 0) {
        l = 0;
        v = 0;
      } else {
        l++;
        v = go[v][q[i]];
      }
      if (l > want) {
        l--;
        if (len[suf[v]] == l) v = suf[v];
      }
      if (l == want) {
        if (last[v] != id) res += dp[v];
        last[v] = id;
      }
    }
    return res;
  }
};
Automaton A;
string s, q;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s;
  s += '$';
  A.build(s);
  A.dfs(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> q;
    cout << A.solve(q, i) << "\n";
  }
  return 0;
}