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>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 1000000009;
}
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
}
template <typename T>
inline T const &MAX(T const &a, T const &b) {
  return a > b ? a : b;
}
template <typename T>
inline T const &MIN(T const &a, T const &b) {
  return a < b ? a : b;
}
inline long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000009;
    a = a * a % 1000000009, b >>= 1;
  }
  return ans;
}
inline long long qp(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = a * a % c, b >>= 1;
  }
  return ans;
}
using namespace std;
const unsigned long long ba = 233;
const double eps = 1e-5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1000000 + 10, maxn = 1000000 + 10, inf = 0x3f3f3f3f;
char s[N], p[N];
struct SAM {
  int last, cnt;
  int ch[N << 1][26], fa[N << 1], l[N << 1], sz[N << 1];
  int a[N << 1], c[N << 1];
  void ins(int x) {
    int p = last, np = ++cnt;
    last = np;
    l[np] = l[p] + 1;
    for (; p && !ch[p][x]; p = fa[p]) ch[p][x] = np;
    if (!p)
      fa[np] = 1;
    else {
      int q = ch[p][x];
      if (l[q] == l[p] + 1)
        fa[np] = q;
      else {
        int nq = ++cnt;
        l[nq] = l[p] + 1;
        memcpy(ch[nq], ch[q], sizeof ch[q]);
        fa[nq] = fa[q];
        fa[q] = fa[np] = nq;
        for (; ch[p][x] == q; p = fa[p]) ch[p][x] = nq;
      }
    }
    sz[np] = 1;
  }
  void topo() {
    for (int i = 1; i <= cnt; i++) c[l[i]]++;
    for (int i = 1; i <= cnt; i++) c[i] += c[i - 1];
    for (int i = 1; i <= cnt; i++) a[c[l[i]]--] = i;
  }
  void build() {
    scanf("%s", s + 1);
    cnt = last = 1;
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++) ins(s[i] - 'a');
    topo();
    for (int i = cnt; i; i--) sz[fa[a[i]]] += sz[a[i]];
  }
} sam;
int fail[N];
int getfail() {
  int k = -1;
  fail[0] = -1;
  for (int i = 1; p[i]; i++) {
    while (k > -1 && p[k + 1] != p[i]) k = fail[k];
    if (p[k + 1] == p[i]) k++;
    fail[i] = k;
  }
  return strlen(p) - 1 - fail[strlen(p) - 1];
}
int main() {
  sam.build();
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s", p);
    int x = getfail(), len = strlen(p);
    if (len % x == 0)
      x -= 2;
    else
      x = len - 2;
    int now = 1, le = 0;
    long long ans = 0;
    for (int j = 0; j < len; j++) {
      while (now && !sam.ch[now][p[j] - 'a'])
        now = sam.fa[now], le = sam.l[now];
      if (!now)
        now = 1, le = 0;
      else
        now = sam.ch[now][p[j] - 'a'], le++;
    }
    if (le == len) ans += sam.sz[now];
    for (int j = 0; j <= x; j++) {
      while (now && !sam.ch[now][p[j] - 'a'])
        now = sam.fa[now], le = sam.l[now];
      if (!now)
        now = 1, le = 0;
      else {
        now = sam.ch[now][p[j] - 'a'];
        le++;
        while (now && sam.l[sam.fa[now]] + 1 > len)
          now = sam.fa[now], le = sam.l[now];
        if (!now) now = 1, le = 0;
      }
      if (le >= len) ans += sam.sz[now];
    }
    printf("%lld\n", ans);
  }
  return 0;
}