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 T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  s << "{";
  for (int i = 0; i < t.size(); i++)
    s << t[i] << (i == t.size() - 1 ? "" : ",");
  return s << "}" << endl;
}
map<char, int> ch_link[2000500];
int size, last, suf_link[2000500], length[2000500], cnt[2000500], vis[2000500];
void init() {
  ch_link[1].clear();
  last = 1, size = 1;
}
void extend(int c) {
  int q, p;
  p = last;
  last = ++size;
  length[last] = length[p] + 1;
  cnt[last] = 1;
  ch_link[size].clear();
  while (p && !((ch_link[p]).find((c)) != (ch_link[p]).end()))
    ch_link[p][c] = last, p = suf_link[p];
  if (!p)
    suf_link[last] = 1;
  else if (length[q = ch_link[p][c]] == length[p] + 1)
    suf_link[last] = q;
  else {
    int clone = ++size;
    length[clone] = length[p] + 1;
    ch_link[clone] = ch_link[q];
    cnt[clone] = 0;
    suf_link[last] = clone;
    suf_link[clone] = suf_link[q];
    suf_link[q] = clone;
    while (p && ch_link[p][c] == q) ch_link[p][c] = clone, p = suf_link[p];
  }
}
vector<int> bylen[2000500];
char s[2000500];
char t[2000500];
int main() {
  ios_base::sync_with_stdio(0);
  scanf("%s", s);
  int n = strlen(s);
  init();
  for (int i = 0; i < n; i++) extend(s[i]);
  for (int i = 2; i <= size; i++) bylen[length[i]].push_back(i);
  for (int i = size; i >= 0; i--)
    for (typeof(bylen[i].begin()) j = bylen[i].begin(); j != bylen[i].end();
         j++)
      cnt[suf_link[*j]] += cnt[*j];
  int query;
  scanf("%d", &(query));
  ;
  for (int q = 1; q <= query; q++) {
    long long wyn = 0;
    scanf("%s", t);
    int d = strlen(t);
    for (int i = 0; i < d; i++) t[i + d] = t[i];
    int pos = 0;
    int dop = 0;
    int u = 1;
    while (pos < d) {
      while (dop < d &&
             ((ch_link[u]).find((t[pos + dop])) != (ch_link[u]).end())) {
        u = ch_link[u][t[pos + dop]];
        dop++;
      }
      if (dop == d) {
        if (vis[u] != q) {
          vis[u] = q;
          wyn += cnt[u];
        }
        if (length[suf_link[u]] >= d - 1) u = suf_link[u];
        dop--;
        pos++;
        continue;
      }
      if (u == 1) {
        dop = 0;
        pos++;
        continue;
      }
      int skok = 0;
      u = suf_link[u];
      if (length[u] < dop) skok = dop - length[u];
      pos += skok;
      dop -= skok;
    }
    cout << wyn << "\n";
  }
  return 0;
}