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>
const int inf = (1ll << 25) - 1;
const int maxn = (int)3e6 + 100;
const int mod = (int)1e9 + 7;
using namespace std;
struct node {
  map<char, int> nxt;
  int len;
  int link;
  int cnt;
  int mx;
} second[maxn];
int N;
int last = 0;
void init() {
  second[0].link = -1;
  second[0].len = 0;
  second[0].nxt.clear();
  N = 1;
  last = 0;
}
void add(char c) {
  int v = N;
  second[v].cnt = 1;
  N++;
  int p = last;
  second[v].nxt.clear();
  second[v].len = second[p].len + 1;
  while (p != -1 && !second[p].nxt.count(c)) {
    second[p].nxt[c] = v;
    p = second[p].link;
  }
  if (p == -1) {
    second[v].link = 0;
  } else {
    int q = second[p].nxt[c];
    if (second[q].len == second[p].len + 1) {
      second[v].link = q;
    } else {
      int cl = N++;
      second[cl].len = second[p].len + 1;
      second[cl].link = second[q].link;
      second[cl].nxt = second[q].nxt;
      while (p != -1 && second[p].nxt[c] == q) {
        second[p].nxt[c] = cl;
        p = second[p].link;
      }
      second[v].link = second[q].link = cl;
    }
  }
  last = v;
}
int cmp(int i, int j) { return second[i].len > second[j].len; }
void calc() {
  vector<int> p;
  for (int i = 0; i < N; i++) p.push_back(i);
  sort(p.begin(), p.end(), cmp);
  for (int i = 0; i < p.size(); i++) {
    if (second[p[i]].link != -1) {
      second[second[p[i]].link].cnt += second[p[i]].cnt;
    }
  }
}
int u[maxn];
int T;
int get(string t) {
  T++;
  int v = 0;
  int ans = 0;
  int L = 0;
  for (int i = 0; i < t.size(); i++) {
    while (v && !second[v].nxt.count(t[i])) {
      v = second[v].link;
      L = second[v].len;
    }
    if (second[v].nxt.count(t[i])) {
      v = second[v].nxt[t[i]];
      L++;
    }
  }
  if (L == t.size()) {
    u[v] = T;
    ans += second[v].cnt;
  }
  for (int i = 0; i < t.size(); i++) {
    if (L == t.size()) {
      L--;
      if (second[second[v].link].len == L) {
        v = second[v].link;
      }
    }
    while (v && !second[v].nxt.count(t[i])) {
      v = second[v].link;
      L = second[v].len;
    }
    if (second[v].nxt.count(t[i])) {
      v = second[v].nxt[t[i]];
      L++;
    }
    if (L == t.size() && u[v] != T) {
      ans += second[v].cnt;
      u[v] = T;
    }
  }
  return ans;
}
void solve() {
  string t;
  cin >> t;
  init();
  for (int i = 0; i < t.size(); i++) add(t[i]);
  calc();
  int x;
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> t;
    cout << get(t) << "\n";
  }
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}