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 MAXN = 1100000;
struct SAM {
  int c[MAXN * 2][26], fa[MAXN * 2], l[MAXN * 2], rt, last, cnt;
  long long siz[MAXN * 2];
  void init() { rt = last = ++cnt; }
  int newnode(int x) {
    l[++cnt] = x;
    return cnt;
  }
  void ins(int x) {
    int p = last, np = newnode(l[p] + 1);
    last = np;
    for (; p && !c[p][x]; p = fa[p]) c[p][x] = np;
    if (!p)
      fa[np] = rt;
    else {
      int q = c[p][x];
      if (l[q] == l[p] + 1)
        fa[np] = q;
      else {
        int nq = newnode(l[p] + 1);
        memcpy(c[nq], c[q], sizeof(c[q]));
        fa[nq] = fa[q];
        fa[q] = fa[np] = nq;
        for (; c[p][x] == q; p = fa[p]) c[p][x] = nq;
      }
    }
    siz[np]++;
  }
  void prepare(int *a, int *cn) {
    for (int i = 0; i <= cnt; i++) cn[i] = 0;
    for (int i = 1; i <= cnt; i++) cn[l[i]]++;
    for (int i = 1; i <= cnt; i++) cn[i] += cn[i - 1];
    for (int i = cnt; i >= 1; --i) a[cn[l[i]]--] = i;
    reverse(a + 1, a + cnt + 1);
    for (int i = 1; i <= cnt; i++) {
      int x = a[i];
      siz[fa[x]] += siz[x];
    }
  }
  long long calc(int n, char *s) {
    static int a[MAXN * 2], cn[MAXN * 2], t;
    static int vis[MAXN * 2];
    vector<int> tmp;
    if (t == 0) prepare(a, cn), t = 1;
    int p = rt, len = 0;
    long long ans = 0;
    for (int he_____he = 0; he_____he < 2; he_____he++) {
      for (int i = 0; i < n; i++) {
        int x = int(s[i] - 'a');
        while (fa[p] && !c[p][x]) p = fa[p], len = l[p];
        if (c[p][x]) p = c[p][x], len++;
        while (l[fa[p]] >= n) p = fa[p], len = l[p];
        ;
        if (vis[p] == 0 && len >= n) {
          ans += siz[p];
          tmp.push_back(p);
          vis[p] = 1;
        }
      }
    }
    for (auto i : tmp) vis[i] = 0;
    return ans;
  }
} S;
int n;
char s[MAXN];
int q, l;
char t[MAXN];
void init() {
  scanf("%s", s);
  n = strlen(s);
  S.init();
  for (int i = 0; i < n; i++) S.ins(s[i] - 'a');
}
void solve() {
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%s", t);
    l = strlen(t);
    printf("%lld\n", S.calc(l, t));
  }
}
int main() {
  init();
  solve();
  return 0;
}