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;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 21;
const int maxn = 2e6 + 10;
const int maxm = 1e5 + 10;
const int base = 29;
const int mod = 1e9 + 7;
const int base2 = 31;
const int mod2 = 1e9 + 9;
const int INF = 2e18 + 100;
const int SQ = 317;
int last;
int sz = 1;
int len[maxn];
int link[maxn];
int nxt[maxn][26];
inline void addLetter(int c) {
  int p = last;
  last = sz++;
  len[last] = len[p] + 1;
  for (; p != -1 && nxt[p][c] == 0; p = link[p]) {
    nxt[p][c] = last;
  }
  if (p == -1) {
    link[last] = 0;
    return;
  }
  int q = nxt[p][c];
  if (len[q] == len[p] + 1) {
    link[last] = q;
    return;
  }
  int cl = sz++;
  for (int j = 0; j < 26; j++) nxt[cl][j] = nxt[q][j];
  link[cl] = link[q];
  len[cl] = len[p] + 1;
  link[q] = link[last] = cl;
  for (; nxt[p][c] == q; p = link[p]) nxt[p][c] = cl;
}
int cnt[maxn];
bool mark[maxn];
inline void calc(int state) {
  if (mark[state]) return;
  mark[state] = true;
  for (int i = 0; i < 26; i++) {
    if (nxt[state][i]) {
      calc(nxt[state][i]);
      cnt[state] += cnt[nxt[state][i]];
    }
  }
}
int kmp[maxn];
inline int repeat(string &t) {
  int tmp = 0;
  for (int i = 1; i < t.size(); i++) {
    while (tmp && t[tmp] != t[i]) tmp = kmp[tmp - 1];
    if (t[tmp] == t[i]) tmp++;
    kmp[i] = tmp;
  }
  int v = (int)t.size() - kmp[(int)t.size() - 1];
  if ((int)t.size() % v == 0) return v;
  return (int)t.size();
}
inline int Count(string &t) {
  int ret = 0;
  int state = 0, ln = 0;
  int lim = repeat(t);
  for (int i = 0; i < (int)t.size() + lim - 1; i++) {
    int cur = i % ((int)t.size());
    while (state != -1 && nxt[state][t[cur] - 'a'] == 0) {
      state = link[state];
      if (state != -1) ln = len[state];
    }
    if (state == -1)
      state = ln = 0;
    else
      state = nxt[state][t[cur] - 'a'], ln++;
    if (ln == t.size()) {
      ret += cnt[state];
      ln--;
      while (link[state] != -1 && len[link[state]] >= ln) state = link[state];
    }
  }
  return ret;
}
int32_t main() {
  link[0] = -1;
  string s = get();
  for (int i = 0; i < s.size(); i++) addLetter(s[i] - 'a');
  for (int p = last; p != -1; p = link[p]) cnt[p]++;
  calc(0);
  int n = in();
  for (int i = 0; i < n; i++) {
    string t = get();
    printf("%d\n", Count(t));
  }
}