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 A = 128;
const int N = (int)2e6 + 10;
const int V = 2 * N;
char str[N];
char query[N];
map<char, int> to[V], link[V];
int pi[N];
int parent[V];
int len[V], pos[V];
int countLeafs[V];
int suffLink[V];
int sz = 2;
int slen = 0;
int qlen = 0;
void attach(int a, int b, int p, int l) {
  to[a][str[p]] = b;
  pos[b] = p;
  len[b] = l;
  parent[b] = a;
}
void expand(char c) {
  int v, index = slen;
  for (v = sz - 1; !link[v].count(c); v = parent[v]) index -= len[v];
  int l = link[v][c];
  if (to[l].count(str[index])) {
    int u = to[l][str[index]];
    pos[sz] = pos[u];
    while (str[pos[sz]] == str[index]) {
      v = to[v][str[index]];
      pos[sz] += len[v];
      index += len[v];
    }
    int newLen = pos[sz] - pos[u];
    link[v][c] = sz;
    attach(l, sz, pos[u], newLen);
    attach(sz, u, pos[u] + newLen, len[u] - newLen);
    l = sz++;
  }
  attach(l, sz++, index, slen - index);
}
void initTree() {
  for (int i = 0; i < A; i++) link[0][i] = to[0][i] = 1;
  parent[1] = 0;
  len[1] = 1;
  pos[1] = 0;
}
void printTree(int v) {
  42;
  42;
  for (auto x : link[v]) 42;
  for (auto x : to[v]) 42;
  for (auto x : to[v]) printTree(x.second);
}
bool goChar(int &vertex, int &edgePosition, char c) {
  if (edgePosition < len[vertex]) {
    if (str[pos[vertex] + edgePosition] == c) {
      edgePosition++;
      return true;
    }
  } else {
    if (to[vertex].count(c)) {
      vertex = to[vertex][c];
      edgePosition = 1;
      return true;
    }
  }
  return false;
}
void goLink(int &vertex, int &edgePosition) {
  if (edgePosition == len[vertex]) {
    vertex = suffLink[vertex];
    edgePosition = len[vertex];
  } else {
    int p = parent[vertex];
    int startPosition = pos[vertex];
    int l = suffLink[p];
    int index = 0;
    while (index < edgePosition) {
      l = to[l][str[startPosition + index]];
      index += len[l];
    }
    vertex = l;
    edgePosition = len[vertex] - (index - edgePosition);
  }
}
void processQuery() {
  int answer = 0;
  int vertex = 1, edgePosition = 1;
  int it = 0;
  for (int i = 1; i < 2 * qlen; i++) {
    int p = pi[i - 1];
    while (p > 0 && query[i] != query[p]) p = pi[p - 1];
    if (query[i] == query[p]) p++;
    pi[i] = p;
  }
  for (int i = 0; i < qlen; i++) {
    while (it - i < qlen && goChar(vertex, edgePosition, query[it])) {
      it++;
    }
    if (pi[i + qlen - 1] >= qlen) break;
    if (it - i == qlen) answer += countLeafs[vertex];
    goLink(vertex, edgePosition);
  }
  printf("%d\n", answer);
}
void calcInfo(int v) {
  if (pos[v] + len[v] == slen) countLeafs[v] = 1;
  for (auto edge : to[v]) {
    int child = edge.second;
    calcInfo(child);
    countLeafs[v] += countLeafs[child];
  }
  for (auto l : link[v]) suffLink[l.second] = v;
}
int main() {
  scanf("%s", str);
  slen = strlen(str);
  str[slen++] = '$';
  initTree();
  for (int i = slen - 1; i >= 0; i--) {
    expand(str[i]);
  }
  suffLink[1] = 0;
  calcInfo(1);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf(" %s", query);
    qlen = strlen(query);
    strcat(query, query);
    processQuery();
  }
  return 0;
}