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;
clock_t __stt;
inline void TStart() { __stt = clock(); }
inline void TReport() {
  printf("\nTaken Time : %.3lf sec\n",
         (double)(clock() - __stt) / CLOCKS_PER_SEC);
}
template <typename T>
T MIN(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
T MAX(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
T ABS(T a) {
  return a > 0 ? a : (-a);
}
template <typename T>
void UMIN(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
void UMAX(T &a, T b) {
  if (b > a) a = b;
}
struct node {
  node *nxt[26], *fa;
  int mxv, rsz, lst;
  void init() {
    lst = -1;
    mxv = 0;
    fa = 0;
    rsz = 0;
    memset(nxt, 0, sizeof(nxt));
  }
  int mnv() { return fa ? (fa->mxv + 1) : 0; }
} * last, *root;
vector<node *> ns;
void extend(int v) {
  node *p = last, *np = new node;
  np->init();
  ns.push_back(np);
  np->mxv = p->mxv + 1;
  for (; p && !p->nxt[v]; p = p->fa) p->nxt[v] = np;
  if (!p)
    np->fa = root;
  else {
    node *q = p->nxt[v];
    if (q->mxv == p->mxv + 1) {
      np->fa = q;
    } else {
      node *nq = new node;
      ns.push_back(nq);
      nq->init();
      nq->mxv = p->mxv + 1;
      memcpy(nq->nxt, q->nxt, sizeof(q->nxt));
      nq->fa = q->fa;
      q->fa = np->fa = nq;
      for (; p && p->nxt[v] == q; p = p->fa) p->nxt[v] = nq;
    }
  }
  last = np;
}
bool cmp(node *A, node *B) { return A->mxv < B->mxv; }
char s[1000005], t[1000005];
int n, q;
int main() {
  int i, j, k;
  scanf("%s", s);
  n = strlen(s);
  last = root = new node;
  ns.resize(1, root);
  root->init();
  for (i = 0; i < n; ++i) {
    extend(s[i] - 'a');
  }
  sort(ns.begin(), ns.end(), cmp);
  node *cur = root;
  for (i = 0; i < n; ++i) {
    cur = cur->nxt[s[i] - 'a'];
    ++cur->rsz;
  }
  for (i = (int)ns.size() - 1; i > 0; --i) {
    ns[i]->fa->rsz += ns[i]->rsz;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%s", t);
    n = strlen(t);
    int res = 0, len = 0;
    cur = root;
    for (i = 0; i < n; ++i) {
      while (cur != root && !(cur->nxt[t[i] - 'a'])) {
        cur = cur->fa;
        len = cur->mxv;
      }
      if (cur->nxt[t[i] - 'a']) {
        cur = cur->nxt[t[i] - 'a'];
        ++len;
      }
    }
    for (i = 0; i < n; ++i) {
      while (cur->mnv() > n) {
        cur = cur->fa;
        len = cur->mxv;
      }
      if (len >= n && cur->lst != q) {
        res += cur->rsz;
        cur->lst = q;
      }
      while (cur != root && !(cur->nxt[t[i] - 'a'])) {
        cur = cur->fa;
        len = cur->mxv;
      }
      if (cur->nxt[t[i] - 'a']) {
        cur = cur->nxt[t[i] - 'a'];
        ++len;
      }
    }
    printf("%d\n", res);
  }
  return 0;
}