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 = 1000005;
int righ[maxn << 1], vis[maxn << 1];
const int ch_size = 26;
struct SAM {
  int fa[maxn * 2], ch[maxn * 2][ch_size], len[maxn * 2], tot, last;
  void init() {
    tot = last = 0;
    fa[0] = -1;
    len[0] = 0;
    memset(ch[0], 0, sizeof(ch[0]));
  }
  void extend(int x) {
    int p = last;
    int cur = ++tot;
    memset(ch[cur], 0, sizeof(ch[cur]));
    len[cur] = len[last] + 1;
    while (p != -1 && !ch[p][x]) {
      ch[p][x] = cur;
      p = fa[p];
    }
    if (p == -1) {
      fa[cur] = 0;
    } else {
      int q = ch[p][x];
      if (len[q] == len[p] + 1) {
        fa[cur] = q;
      } else {
        int clone = ++tot;
        len[clone] = len[p] + 1;
        for (int i = 0; i < ch_size; i++) {
          ch[clone][i] = ch[q][i];
        }
        fa[clone] = fa[q];
        fa[q] = fa[cur] = clone;
        while (p != -1) {
          if (ch[p][x] == q)
            ch[p][x] = clone;
          else
            break;
          p = fa[p];
        }
      }
    }
    last = cur;
  }
} g;
char str[maxn];
int c[maxn], b[maxn << 1];
void radix(int len) {
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= g.tot; i++) c[g.len[i]]++;
  for (int i = 2; i <= len; i++) c[i] += c[i - 1];
  for (int i = 1; i <= g.tot; i++) b[c[g.len[i]]--] = i;
}
int tim;
int solve() {
  int len = strlen(str), p = 0, cnt = 0, res = 0, sum = 0, j = 0;
  while (cnt < 2) {
    if (j == len - 1) cnt++;
    if (cnt >= 2) break;
    int c = str[j] - 'a';
    if (g.ch[p][c]) {
      p = g.ch[p][c];
      sum++;
      if (sum == len) {
        if (vis[p] != tim) res += righ[p];
        vis[p] = tim;
        sum--;
        if (g.len[g.fa[p]] >= sum) {
          p = g.fa[p];
        }
      }
    } else {
      while (p != -1 && !g.ch[p][c]) {
        p = g.fa[p];
        sum = g.len[p];
      }
      if (p == -1) break;
      p = g.ch[p][c];
      sum++;
    }
    j = (j + 1) % len;
  }
  return res;
}
int main() {
  scanf("%s", str);
  int len = strlen(str);
  g.init();
  for (int i = 0; i < len; i++) {
    g.extend(str[i] - 'a');
    righ[g.last] = 1;
  }
  radix(len);
  for (int i = g.tot; i >= 1; i--) {
    int j = b[i];
    righ[g.fa[j]] += righ[j];
  }
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    tim++;
    scanf("%s", str);
    int ans = solve();
    printf("%d\n", ans);
  }
  return 0;
}