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 MX = 1e6;
struct SuffixAutomaton {
  int len[2 * MX];
  int link[2 * MX];
  map<int, int> to[2 * MX];
  bool terminal[2 * MX];
  int last;
  int sz;
  bool vis[2 * MX];
  SuffixAutomaton() {
    last = 0;
    sz = 1;
    link[0] = -1;
    len[0] = 0;
  }
  void addLetter(char c) {
    int p = last;
    last = sz++;
    len[last] = len[p] + 1;
    while (p != -1 && to[p][c] == 0) {
      to[p][c] = last;
      p = link[p];
    }
    if (p == -1) {
      link[last] = 0;
      return;
    }
    int q = to[p][c];
    if (len[q] == len[p] + 1) {
      link[last] = q;
      return;
    }
    int clone = sz++;
    to[clone] = to[q];
    link[clone] = link[q];
    link[last] = link[q] = clone;
    len[clone] = len[p] + 1;
    while (p != -1 && to[p][c] == q) {
      to[p][c] = clone;
      p = link[p];
    }
  }
  void markTerminal() {
    int u = last;
    while (u != 0) {
      terminal[u] = true;
      u = link[u];
    }
  }
  void build(string &s) {
    for (char c : s) addLetter(c);
    markTerminal();
  }
  int dp[2 * MX];
  bool used[2 * MX];
  int countPath(int u) {
    if (used[u]) {
      return dp[u];
    }
    used[u] = true;
    dp[u] = terminal[u];
    for (auto transition : to[u]) {
      int v = transition.second;
      assert(v != 0);
      dp[u] += countPath(v);
    }
    return dp[u];
  }
  long long countCyclic(string &t) {
    int node = 0;
    long long ans = 0;
    int curLen = 0;
    int sz = t.size();
    t += t;
    vector<int> nodes;
    for (int i = 0; i < t.size(); i++) {
      while (node > 0 && to[node].find(t[i]) == to[node].end()) {
        node = link[node];
        curLen = len[node];
      }
      if (to[node].find(t[i]) != to[node].end()) {
        node = to[node][t[i]];
        curLen++;
      } else {
        curLen = 0;
      }
      while (curLen >= sz && len[link[node]] >= sz) {
        node = link[node];
        curLen = len[node];
      }
      if (i >= sz && curLen >= sz && !vis[node]) {
        ans += countPath(node);
        vis[node] = true;
        nodes.push_back(node);
      }
    }
    for (int u : nodes) {
      vis[u] = false;
    }
    return ans;
  }
} automaton;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  automaton.build(s);
  long long Q;
  cin >> Q;
  for (long long i = 0; i < (long long)Q; i++) {
    string p;
    cin >> p;
    cout << automaton.countCyclic(p) << "\n";
  }
  return 0;
}