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;
struct SuffixAutomaton {
  int len[2 * 1000100], link[2 * 1000100], cnt[2 * 1000100];
  int nxt[2 * 1000100][26], sz, last, root;
  int newnode() {
    int x = ++sz;
    len[x] = 0;
    link[x] = -1;
    cnt[x] = 1;
    for (int c = 0; c < 26; c++) nxt[x][c] = 0;
    return x;
  }
  inline int reduce(char c) { return c - 'a'; }
  SuffixAutomaton() { clear(); }
  void clear() {
    sz = 0;
    root = last = newnode();
  }
  void insert(string &s) {
    for (char &c : s) extend(reduce(c));
  }
  void extend(int c) {
    int cur = newnode(), p;
    len[cur] = len[last] + 1;
    for (p = last; p != -1 && !nxt[p][c]; p = link[p]) {
      nxt[p][c] = cur;
    }
    if (p == -1)
      link[cur] = root;
    else {
      int q = nxt[p][c];
      if (len[p] + 1 == len[q])
        link[cur] = q;
      else {
        int clone = newnode();
        len[clone] = len[p] + 1;
        for (int i = 0; i < 26; i++) nxt[clone][i] = nxt[q][i];
        link[clone] = link[q];
        cnt[clone] = 0;
        while (p != -1 && nxt[p][c] == q) {
          nxt[p][c] = clone;
          p = link[p];
        }
        link[q] = link[cur] = clone;
      }
    }
    last = cur;
  }
  int deg[2 * 1000100];
  void computeCnt() {
    fill(deg, deg + sz + 1, 0);
    for (int i = root + 1; i <= sz; i++) deg[link[i]]++;
    queue<int> q;
    for (int i = root + 1; i <= sz; i++)
      if (deg[i] == 0) q.push(i);
    while (!q.empty()) {
      int i = q.front();
      q.pop();
      if (i <= root) continue;
      int j = link[i];
      cnt[j] += cnt[i];
      if ((--deg[j]) == 0) q.push(j);
    }
  }
  int nmatches(string &s) {
    int p = root;
    for (int i = 0; i < s.size(); i++) {
      int c = reduce(s[i]);
      if (!nxt[p][c]) return 0;
      p = nxt[p][c];
    }
    return cnt[p];
  }
} SA;
int n, sz;
char s[1000100];
string str, pat;
void z_function(string &s, int *z) {
  for (int i = 1, L = 0, R = 0; i < s.size(); i++) {
    if (i > R) L = R = i;
    z[i] = min(R - i, z[i - L]);
    while (i + z[i] < s.size() && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] > R) L = i, R = i + z[i];
  }
}
int z[2000100];
bool ok(int id) { return (id < sz || z[id - sz + 1] < sz); }
int main() {
  scanf("%s", s);
  str = s;
  SA.insert(str);
  SA.computeCnt();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    pat = s;
    sz = pat.size();
    pat += pat;
    pat.pop_back();
    z_function(pat, z);
    int ans = 0, v = 1, l = 0;
    for (int j = 0; j < pat.size(); j++) {
      int idx = pat[j] - 'a';
      while (v > 1 && (!SA.nxt[v][idx] || SA.len[SA.link[v]] >= sz - 1)) {
        v = SA.link[v];
        l = SA.len[v];
      }
      if (SA.nxt[v][idx]) {
        v = SA.nxt[v][idx];
        l++;
      }
      if (!ok(j)) {
        break;
      }
      if (l >= sz) ans += SA.cnt[v];
    }
    printf("%d\n", ans);
  }
  return 0;
}