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;
int nx[1000514 * 2][26], spt;
int fl[1000514 * 2], ll[1000514 * 2], lp[1000514 * 2];
int newnode() {
  memset(nx[spt], 0, sizeof(nx[spt]));
  fl[spt] = ll[spt] = lp[spt] = 0;
  return spt++;
}
int dp[1000514 * 2];
void add(int root, int& last, char A) {
  int a = A - 'a';
  int p = last;
  int np = last = newnode();
  ll[np] = ll[p] + 1;
  lp[np] = 0;
  dp[np] = 1;
  for (; p && nx[p][a] == 0; p = fl[p]) nx[p][a] = np;
  int q = nx[p][a];
  if (p == 0)
    fl[np] = root;
  else if (ll[q] == ll[p] + 1)
    fl[np] = q;
  else {
    int nq = spt++;
    memcpy(nx[nq], nx[q], sizeof(nx[q]));
    fl[nq] = fl[q];
    ll[nq] = ll[p] + 1;
    lp[nq] = lp[q] + ll[q] - 1 - ll[p];
    fl[q] = fl[np] = nq;
    for (; p && nx[p][a] == q; p = fl[p]) nx[p][a] = nq;
  }
}
char s[1000514], r[1000514 * 2];
vector<int> bk[1000514];
int vs[1000514 * 2], vt;
void make_z(int* z, char* s, int l) {
  int j = z[0] = 0;
  for (int i = 1; i < l; i++) {
    z[i] = (i > j + z[j] - 1) ? 0 : min(z[i - j], j + z[j] - i);
    for (; i + z[i] < l && s[z[i]] == s[i + z[i]]; z[i]++)
      ;
    if (i + z[i] > j + z[j]) j = i;
  }
}
int z[1000514 * 2];
void sol() {
  spt = 1;
  int last;
  int root = last = newnode();
  int sl = 0;
  for (; s[sl]; sl++)
    ;
  for (int i = 0; i < sl; i++) add(root, last, s[i]);
  for (int i = 1; i < spt; i++) {
    bk[ll[i]].push_back(i);
  }
  for (int i = sl; i >= 0; i--) {
    int sz = (int)bk[i].size();
    for (int j = 0; j < sz; j++) {
      int w = bk[i][j];
      dp[fl[w]] += dp[w];
    }
  }
  int Q;
  scanf("%d", &Q);
  for (int T = 0; T < Q; T++) {
    scanf("%s", r);
    int rl = 0;
    for (; r[rl]; rl++)
      ;
    for (int i = 0; i < rl; i++) r[rl + i] = r[i];
    r[rl + rl] = 0;
    make_z(z, r, rl * 2);
    int t = 0;
    for (int i = 1; i <= rl; i++) {
      if (rl % i) continue;
      int flag = 0;
      for (int j = i; j < rl; j += i) {
        if (z[j] < i) {
          flag = 1;
        }
      }
      if (flag) continue;
      t = i;
      break;
    }
    int p = root;
    int l = 0;
    for (int i = 0; i < rl; i++) {
      int a = r[i] - 'a';
      for (; p && nx[p][a] == 0; p = fl[p])
        ;
      if (p == 0) {
        l = 0;
        p = root;
      } else {
        l = min(l, ll[p]) + 1;
        p = nx[p][a];
      }
    }
    vt++;
    int ans = 0;
    if (l >= rl && vs[p] != vt) {
      ans += dp[p];
    }
    for (int i = 0; i < rl - 1; i++) {
      int a = r[i] - 'a';
      for (; p && nx[p][a] == 0; p = fl[p])
        ;
      if (p == 0) {
        l = 0;
        p = root;
      } else {
        l = min(l, ll[p]) + 1;
        p = nx[p][a];
      }
      for (; p && ll[fl[p]] >= rl; p = fl[p])
        ;
      l = min(l, ll[p]);
      if (l >= rl && vs[p] != vt) {
        ans += dp[p];
      }
    }
    printf("%d\n", (int)ans / (rl / t));
  }
}
int main() {
  scanf("%s", s);
  sol();
}