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 <class T>
bool umax(T &x, T y) {
  return (x < y) ? x = y, true : false;
}
template <class T>
bool umin(T &x, T y) {
  return (x > y) ? x = y, true : false;
}
struct SAM {
  struct state {
    int fa, len;
    vector<int> nxt;
  };
  vector<state> m;
  vector<int> R, idx, cnt;
  void init() {
    m.assign(2, {0, 0, vector<int>(26)});
    R.assign(2, 0);
  }
  int add() {
    m.resize(m.size() + 1);
    R.push_back(0);
    return m.size() - 1;
  }
  int touch(int x, int c) {
    int y = m[x].nxt[c], len = m[x].len + 1;
    if (y) {
      if (m[y].len == len) return y;
      int z = add();
      m[z] = {m[y].fa, len, m[y].nxt};
      for (m[y].fa = z; m[x].nxt[c] == y; x = m[x].fa) m[x].nxt[c] = z;
      return z;
    } else {
      y = add();
      for (; x && !m[x].nxt[c]; x = m[x].fa) m[x].nxt[c] = y;
      int fa = (!x) ? 1 : touch(x, c);
      m[y] = {fa, len, m[0].nxt};
      return y;
    }
  }
  int extend(int x, int c) {
    int res = touch(x, c);
    return R[res]++, res;
  }
  void index() {
    idx.assign(m.size(), 0);
    cnt.assign(m.size(), 0);
    for (int i = 0; i < (m.size()); i++) cnt[m[i].len]++;
    for (int i = (1); i < (m.size()); i++) cnt[i] += cnt[i - 1];
    for (int i = (m.size()) - 1; i >= 0; i--) idx[--cnt[m[i].len]] = i;
  }
  void calcR() {
    for (int i = (m.size()) - 1; i >= (2); i--) R[m[idx[i]].fa] += R[idx[i]];
  }
  long long solve(string &s) {
    int sx = -1, x = 1, len = 0, tar = ((int)(s).length());
    s = s + s;
    long long res = 0;
    for (auto c : s) {
      c -= 'a';
      while (x && !m[x].nxt[c]) x = m[x].fa, len = m[x].len;
      if (!x)
        x = 1, len = 0;
      else
        x = m[x].nxt[c], ++len;
      if (m[m[x].fa].len >= tar) x = m[x].fa, len = m[x].len;
      if (len >= tar) {
        if (x == sx) break;
        if (sx == -1) sx = x;
        res += R[x];
      }
    }
    return res;
  }
} sam;
void input() {
  string s;
  cin >> s;
  sam.init();
  int last = 1;
  for (auto c : s) last = sam.extend(last, c - 'a');
  sam.index();
  sam.calcR();
}
void output() {
  int q;
  for (cin >> q; q--;) {
    string t;
    cin >> t;
    cout << sam.solve(t) << endl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  input();
  output();
  return 0;
}