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 N = 1e5 + 5;
const int L = 1e6 + 5;
namespace SAM {
const int T = L << 1;
struct Node {
  map<char, int> ch;
  int link, len, size;
} t[T];
int last;
int total;
void extend_char(char c) {
  int p = last, np = last = ++total;
  t[np].len = t[p].len + 1;
  for (; p && !t[p].ch[c]; p = t[p].link) t[p].ch[c] = np;
  if (!p) {
    t[np].link = 1;
  } else {
    int q = t[p].ch[c];
    if (t[p].len + 1 == t[q].len) {
      t[np].link = q;
    } else {
      int nq = ++total;
      t[nq] = t[q], t[nq].len = t[p].len + 1, t[nq].size = 0;
      t[np].link = t[q].link = nq;
      for (; p && t[p].ch[c] == q; p = t[p].link) t[p].ch[c] = nq;
    }
  }
  t[np].size = 1;
}
int b[T], c[T];
void init_data(string& s) {
  last = total = 1;
  for (string::iterator it = s.begin(); it != s.end(); it++) extend_char(*it);
  for (register int i = 1; i <= total; i++) ++c[t[i].len];
  for (register int i = 1; i <= total; i++) c[i] += c[i - 1];
  for (register int i = 1; i <= total; i++) b[c[t[i].len]--] = i;
  for (register int i = total; i; i--) {
    int x = b[i], f = t[x].link;
    t[f].size += t[x].size;
  }
}
int vis[T];
long long count(string& str, int time);
};  // namespace SAM
long long SAM::count(string& str, int time) {
  long long ret = 0ll;
  int x = 1, len = 0;
  str = str + str;
  for (register int i = 0; i < str.size(); i++) {
    char c = str[i];
    while (x && !t[x].ch[c]) x = t[x].link, len = t[x].len;
    if (!x)
      x = 1, len = 0;
    else
      x = t[x].ch[c], len++;
    while (x && t[t[x].link].len >= str.size() / 2)
      x = t[x].link, len = t[x].len;
    if (len >= str.size() / 2 && vis[x] != time)
      ret += t[x].size, vis[x] = time;
  }
  return ret;
}
signed main() {
  ios::sync_with_stdio(false);
  string str;
  cin >> str;
  SAM::init_data(str);
  int m;
  cin >> m;
  for (register int time = 1; time <= m; time++) {
    cin >> str;
    cout << SAM::count(str, time) << endl;
  }
  return 0;
}