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;
#pragma GCC optimize("O3")
#pragma comment(linker, "/STACK:32505856")
template <class T>
inline T sqr(T a) {
  return a * a;
}
template <class T>
inline void gmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void gmax(T &a, T b) {
  if (a < b) a = b;
}
inline int dcmp(const double &a) { return a > 1e-8 ? 1 : (a < -1e-8 ? -1 : 0); }
struct Initializer {
  Initializer() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  }
} initializer;
struct SAM {
  int tot, last;
  int go[1000010 << 1][26], pre[1000010 << 1], step[1000010 << 1];
  int vis[1000010 << 1];
  long long same[1000010 << 1];
  inline void new_node(int s) {
    step[++tot] = s;
    pre[tot] = 0;
    same[tot] = 1;
    memset(go[tot], 0, sizeof(go[tot]));
  }
  inline void build(char *s) {
    tot = 0, last = 1;
    new_node(0);
    int n = strlen(s);
    for (int i = 0; i <= n - 1; i++) {
      new_node(step[last] + 1);
      int c = s[i] - 'a';
      int p = last, np = tot, q, nq;
      for (; p && !go[p][c]; p = pre[p]) go[p][c] = np;
      if (!p)
        pre[np] = 1;
      else {
        q = go[p][c];
        if (step[q] == step[p] + 1)
          pre[np] = q;
        else {
          new_node(step[p] + 1), nq = tot;
          for (int j = 0; j <= 25; j++) go[nq][j] = go[q][j];
          pre[nq] = pre[q];
          pre[np] = pre[q] = nq;
          same[nq] = 0;
          for (; p && go[p][c] == q; p = pre[p]) go[p][c] = nq;
        }
      }
      last = np;
    }
  }
  int din[1000010 << 1], q[1000010 << 1], top, tail;
  inline void get_same() {
    top = tail = 0;
    for (int i = 1; i <= tot; i++) din[pre[i]]++;
    for (int i = tot; i >= 1; i--)
      if (!din[i]) q[++tail] = i;
    while (++top <= tail) {
      int first = q[top];
      if (!--din[pre[first]]) q[++tail] = pre[first];
      same[pre[first]] += same[first];
    }
  }
  inline long long get_ans(char *s, int n, int tag) {
    long long res = 0;
    int p = 1, len = 0;
    for (int i = 0; i <= n + n - 2; i++) {
      int c = s[i] - 'a';
      if (!go[p][c]) {
        while (p && !go[p][c]) p = pre[p];
        len = step[p];
      }
      if (go[p][c]) {
        p = go[p][c];
        len++;
      }
      if (len >= n) {
        int q = p;
        while (!(step[pre[q]] + 1 <= n && n <= step[q])) {
          if (vis[q] == tag) goto next;
          vis[q] = tag;
          q = pre[q];
        }
        if (vis[q] != tag) {
          vis[q] = tag;
          res += same[q];
        }
      next:;
      }
    }
    return res;
  }
} sam;
int main() {
  static char s[1000010], t[1000010 << 1];
  scanf("%s", s);
  sam.build(s);
  sam.get_same();
  int n, m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s", t);
    n = strlen(t);
    memcpy(t + n, t, n);
    t[n + n] = 0;
    printf("%I64d\n", sam.get_ans(t, n, i));
  }
  return 0;
}