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;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
void tr() { cout << endl; }
template <typename S, typename... Strings>
void tr(S x, const Strings&... rest) {
  cout << x << ' ';
  tr(rest...);
}
const int N = 1001000;
const int M = 26;
struct suffixAutomaton {
  struct state {
    int len, link;
    int next[M];
    long long cnt;
    bool terminal;
    state() {
      len = 0, link = -1, cnt = 0;
      terminal = false;
      for (int i = 0; i < M; i++) next[i] = -1;
    }
  };
  state st[N * 2];
  int sz, last;
  char offset = 'a';
  suffixAutomaton(string& s) {
    int l = s.length();
    for (int i = 0; i < 2 * l; i++) st[i] = state();
    sz = 1, last = 0;
    st[0].len = 0;
    st[0].link = -1;
    for (int i = 0; i < l; i++) addChar(s[i] - offset);
    for (int i = last; i != -1; i = st[i].link) st[i].terminal = true;
  }
  void addChar(int c) {
    int cur = sz++;
    assert(cur < N * 2);
    st[cur].len = st[last].len + 1;
    st[cur].cnt = 1;
    int p = last;
    while (p != -1 and st[p].next[c] == -1) {
      st[p].next[c] = cur;
      p = st[p].link;
    }
    last = cur;
    if (p == -1) {
      st[cur].link = 0;
      return;
    }
    int q = st[p].next[c];
    if (st[q].len == st[p].len + 1) {
      st[cur].link = q;
      return;
    }
    int clone = sz++;
    for (int i = 0; i < M; i++) st[clone].next[i] = st[q].next[i];
    st[clone].link = st[q].link;
    st[clone].len = st[p].len + 1;
    st[clone].cnt = 0;
    while (p != -1 and st[p].next[c] == q) {
      st[p].next[c] = clone;
      p = st[p].link;
    }
    st[q].link = st[cur].link = clone;
    return;
  }
  long long h[2 * N], p[2 * N];
  long long base = 29, pr = 1e9 + 7;
  unordered_set<long long> done;
  void numberOfOccPreprocess() {
    vector<pair<int, int> > v;
    for (int i = 1; i < sz; i++) v.push_back(make_pair(st[i].len, i));
    sort(v.begin(), v.end(), greater<pair<int, int> >());
    for (int i = 0; i < sz - 1; i++) {
      int suf = st[v[i].second].link;
      st[suf].cnt += st[v[i].second].cnt;
    }
    p[0] = 1;
    for (int i = 1; i < 2 * N; i++) p[i] = (p[i - 1] * base) % pr;
  }
  long long numberOfOcc(string& t) {
    long long res = 0;
    int l = 0, m = t.length();
    done.clear();
    string tmp = t + t;
    h[0] = 0;
    for (int i = 1; i <= 2 * m; i++)
      h[i] = ((h[i - 1] * base) + (tmp[i - 1] - offset + 1)) % pr;
    int cur = 0, nxt;
    for (int i = 0; i < 2 * m - 1; i++) {
      while (cur != 0 and st[cur].next[tmp[i] - offset] == -1) {
        cur = st[cur].link;
        l = st[cur].len;
      }
      nxt = st[cur].next[tmp[i] - offset];
      if (nxt == -1)
        nxt = 0, l = 0;
      else
        l++;
      cur = nxt;
      if (l > m) {
        if (l - 1 == st[st[cur].link].len) cur = st[cur].link;
        l--;
      }
      if (l == m) {
        long long v1 = h[i + 1];
        long long v2 = (h[i + 1 - m] * p[m]) % pr;
        v1 = (v1 - v2 + pr) % pr;
        if (!done.count(v1)) {
          res += st[cur].cnt;
          done.insert(v1);
        }
      }
    }
    return res;
  }
};
string s;
string t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  suffixAutomaton* suf = new suffixAutomaton(s);
  suf->numberOfOccPreprocess();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    cout << suf->numberOfOcc(t) << '\n';
  }
  return 0;
}