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 iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const long long linf = 1ll << 60;
const double dinf = 1e60;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
  scf(x);
  scf(y);
  scf(z);
  return scf(w);
}
inline char mygetchar() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
template <typename T>
inline bool chkmax(T &x, const T &y) {
  return y > x ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T &x, const T &y) {
  return y < x ? x = y, 1 : 0;
}
const int maxn = 1e6 + 10;
struct node {
  node *go[26], *par;
  int len, siz, tag;
  node() {
    memset(go, 0, sizeof go);
    par = 0;
    len = siz = tag = 0;
  }
  inline void cpy(node *u) {
    memcpy(go, u->go, sizeof go);
    par = u->par;
    return;
  }
} * root, *last;
vector<node *> lvl[maxn];
char s[maxn];
inline void expand(int id) {
  node *p = last, *np = new node;
  np->len = p->len + 1;
  np->siz = 1;
  while (p && !p->go[id]) p->go[id] = np, p = p->par;
  if (!p)
    np->par = root;
  else {
    node *q = p->go[id];
    if (q->len == p->len + 1)
      np->par = q;
    else {
      node *nq = new node;
      nq->cpy(q);
      q->par = np->par = nq;
      nq->len = p->len + 1;
      while (p && p->go[id] == q) p->go[id] = nq, p = p->par;
    }
  }
  last = np;
  return;
}
inline void dfs(node *u) {
  if (!~u->tag) return;
  u->tag = -1;
  lvl[u->len].push_back(u);
  for (int i = 0, _end_ = (26); i < _end_; ++i)
    if (u->go[i]) dfs(u->go[i]);
  return;
}
int main() {
  root = new node;
  last = root;
  char c = getchar();
  while (c < 'a' || c > 'z') c = getchar();
  while (c >= 'a' && c <= 'z') expand(c - 'a'), c = getchar();
  dfs(root);
  for (int i = last->len; i; --i)
    for (int j = 0, _end_ = ((int)lvl[i].size()); j < _end_; ++j)
      if (lvl[i][j]->par) lvl[i][j]->par->siz += lvl[i][j]->siz;
  int q;
  scf(q);
  while (q--) {
    scanf("%s", s);
    int n = strlen(s), matched = 0, ans = 0;
    node *u = root;
    for (int i = 0, _end_ = (n << 1); i < _end_; ++i) {
      int id = s[i % n] - 'a';
      while (u && !u->go[id]) u = u->par, matched = u ? u->len : 0;
      if (!u)
        u = root;
      else {
        u = u->go[id];
        ++matched;
        while (u->par && u->par->len >= n) u = u->par, matched = u->len;
        if (matched >= n && u->tag != q) u->tag = q, ans += u->siz;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}