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 MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e6 + 4;
const int maxm = 1e3 + 4;
const double pi = acos(-1.0);
struct SuffixAutoMachine {
  int trans[maxn][26], maxlen[maxn], link[maxn], cnt, lst;
  int times[maxn], in[maxn], mark[maxn];
  inline int id(char x) { return x - 'a'; }
  void newNode() {
    cnt++;
    memset(trans[cnt], -1, sizeof trans[cnt]);
    link[cnt] = -1;
    times[cnt] = 0;
    return;
  }
  void insert(int id) {
    newNode();
    maxlen[cnt] = maxlen[lst] + 1;
    times[cnt] = 1;
    int u = lst;
    while (u != -1 && trans[u][id] == -1) {
      trans[u][id] = cnt;
      u = link[u];
    }
    if (u == -1) {
      link[cnt] = 0;
      lst = cnt;
      return;
    }
    int q = trans[u][id];
    if (maxlen[q] == maxlen[u] + 1) {
      link[cnt] = q;
      lst = cnt;
      return;
    }
    int cur = cnt, sq = cnt + 1;
    newNode();
    maxlen[sq] = maxlen[u] + 1;
    memcpy(trans[sq], trans[q], sizeof trans[q]);
    link[sq] = link[q];
    link[q] = sq;
    link[cur] = sq;
    lst = cur;
    times[sq] = 0;
    while (u != -1 && trans[u][id] == q) {
      trans[u][id] = sq;
      u = link[u];
    }
    return;
  }
  void init() {
    cnt = -1;
    newNode();
    maxlen[0] = 0;
    lst = 0;
    memset(in, 0, sizeof in);
    memset(mark, -1, sizeof mark);
  }
  void construct(char* s) {
    init();
    for (int i = 0; s[i]; ++i) insert(id(s[i]));
    for (int i = 1; i <= cnt; ++i) in[link[i]]++;
    queue<int> q;
    for (int i = 1; i <= cnt; ++i)
      if (!in[i]) q.push(i);
    while (q.size()) {
      int top = q.front();
      q.pop();
      if (top == 0) continue;
      times[link[top]] += times[top];
      if (--in[link[top]] == 0) q.push(link[top]);
    }
  }
  long long match(int idx, char* s, int n) {
    for (int i = 0; i < n; ++i) s[i + n] = s[i];
    s[n + n] = 0;
    long long ret = 0;
    int len = 0, cur = 0;
    for (int i = 0; s[i]; ++i) {
      if (cur != 0) {
        int bef = link[cur];
        if (maxlen[bef] == n - 1) {
          cur = bef, len = n - 1;
        }
      }
      int nxt = id(s[i]);
      while (cur != 0 && trans[cur][nxt] == -1) {
        cur = link[cur];
        len = maxlen[cur];
      }
      if (trans[cur][nxt] != -1) {
        cur = trans[cur][nxt];
        len++;
      }
      if (len >= n && mark[cur] != idx) {
        mark[cur] = idx;
        ret += times[cur];
      }
    }
    return ret;
  }
} SAM;
char s[maxn];
int n;
int main() {
  int ik, i, j, k, kase;
  scanf("%s", s);
  SAM.construct(s);
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%s", s);
    printf("%lld\n", SAM.match(i, s, strlen(s)));
  }
  return 0;
}