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>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
struct Node {
  vi to;
  int mxln;
  int lk;
  Node() : to(27, -1), mxln(0), lk(-1) {}
  Node(int mxln) : to(27, -1), mxln(mxln), lk(-1) {}
  Node(const vi& to, int mxln, int lk) : to(to), mxln(mxln), lk(lk) {}
};
vector<Node> au(1);
int lst;
void append(char ch) {
  ch -= 'a';
  int cur = (int)((au).size());
  au.emplace_back(au[lst].mxln + 1);
  int pv = lst;
  for (; pv != -1 && au[pv].to[ch] == -1; pv = au[pv].lk) {
    au[pv].to[ch] = cur;
  }
  if (pv == -1) {
    au[cur].lk = 0;
  } else {
    int nxt = au[pv].to[ch];
    if (au[nxt].mxln == au[pv].mxln + 1) {
      au[cur].lk = nxt;
    } else {
      int cl = (int)((au).size());
      au.emplace_back(au[nxt].to, au[pv].mxln + 1, au[nxt].lk);
      au[cur].lk = au[nxt].lk = cl;
      for (; pv != -1 && au[pv].to[ch] == nxt; pv = au[pv].lk) {
        au[pv].to[ch] = cl;
      }
    }
  }
  lst = cur;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  s.insert(s.begin(), 'z' + 1);
  int n = (int)((s).size());
  for (auto ch : s) {
    append(ch);
  }
  vector<pii> ord((int)((au).size()));
  for (int i = 0; i < (int)((au).size()); i++) {
    ord[i] = make_pair(au[i].mxln, i);
  }
  sort((ord).begin(), (ord).end());
  reverse((ord).begin(), (ord).end());
  ord.pop_back();
  vi lfs((int)((au).size()));
  for (auto v : ord) {
    if (!lfs[v.second]) lfs[v.second] = 1;
    lfs[au[v.second].lk] += lfs[v.second];
  }
  int q;
  cin >> q;
  vi lt((int)((au).size()));
  int ct = 0;
  while (q--) {
    string t;
    cin >> t;
    int len = (int)((t).size());
    t += t;
    ct++;
    int ans = 0;
    int v = 0;
    for (int i = 0, r = -1; i < len; i++) {
      while (r - i + 1 < len && au[v].to[t[r + 1] - 'a'] != -1) {
        r++;
        v = au[v].to[t[r] - 'a'];
      }
      if (r - i + 1 == len) {
        if (lt[v] != ct) {
          ans += lfs[v];
          lt[v] = ct;
        }
      }
      if (au[au[v].lk].mxln == r - i) {
        v = au[v].lk;
      }
    }
    cout << ans << '\n';
  }
}