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>
const int maxn = 1e6 + 10;
const int maxm = 1e5 + 10;
const long long int mod = 1e9 + 7;
const long long int INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int n, m;
int cas, tol, T;
struct Sam {
  int node[maxn << 1][27], step[maxn << 1], fa[maxn << 1];
  int dp[maxn << 1], tax[maxn << 1], gid[maxn << 1];
  int vis[maxn << 1];
  int last, sz;
  int newnode() {
    memset(node[++sz], 0, sizeof node[++sz]);
    dp[sz] = step[sz] = fa[sz] = 0;
    return sz;
  }
  void init() {
    sz = 0;
    last = newnode();
  }
  void insert(int k) {
    int p = last, np = last = newnode();
    dp[np] = 1;
    step[np] = step[p] + 1;
    for (; p && !node[p][k]; p = fa[p]) node[p][k] = np;
    if (p == 0) {
      fa[np] = 1;
    } else {
      int q = node[p][k];
      if (step[q] == step[p] + 1) {
        fa[np] = q;
      } else {
        int nq = newnode();
        memcpy(node[nq], node[q], sizeof(node[q]));
        fa[nq] = fa[q];
        step[nq] = step[p] + 1;
        fa[np] = fa[q] = nq;
        for (; p && node[p][k] == q; p = fa[p]) node[p][k] = nq;
      }
    }
  }
  void handle() {
    for (int i = 0; i <= sz; i++) tax[i] = 0;
    for (int i = 1; i <= sz; i++) tax[step[i]]++;
    for (int i = 1; i <= sz; i++) tax[i] += tax[i - 1];
    for (int i = 1; i <= sz; i++) gid[tax[step[i]]--] = i;
    for (int i = sz; i >= 1; i--) {
      int u = gid[i];
      dp[fa[u]] += dp[u];
    }
  }
  int solve(char *s, int len, int id) {
    int p = 1, res = 0;
    int ans = 0;
    for (int i = 1; i <= len + len; i++) {
      int k = s[i] - 'a' + 1;
      while (p && !node[p][k]) {
        p = fa[p];
        res = step[p];
      }
      if (p == 0) {
        p = 1;
        res = 0;
      } else {
        p = node[p][k];
        res++;
        if (res >= len) {
          int tmp = p;
          while (tmp && vis[tmp] != id &&
                 !(step[fa[tmp]] + 1 <= len && len <= step[tmp])) {
            vis[tmp] = id;
            tmp = fa[tmp];
          }
          if (vis[tmp] != id) {
            vis[tmp] = id;
            ans += dp[tmp];
          }
        }
      }
    }
    return ans;
  }
} sam;
char s[maxn], t[maxn << 1];
int main() {
  scanf("%s", s + 1);
  int slen = strlen(s + 1);
  sam.init();
  for (int i = 1; i <= slen; i++) {
    sam.insert(s[i] - 'a' + 1);
  }
  sam.handle();
  scanf("%d", &T);
  for (int tt = 1; tt <= T; tt++) {
    scanf("%s", t + 1);
    int tlen = strlen(t + 1);
    for (int i = 1; i <= tlen; i++) {
      t[i + tlen] = t[i];
    }
    t[tlen + tlen + 1] = '\0';
    int ans = sam.solve(t, tlen, tt);
    printf("%d\n", ans);
  }
  return 0;
}