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;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
struct SuffixAutomaton {
  static const int M = 2000010;
  int sz, lst;
  int ch[M][26];
  int len[M], link[M];
  int cntPos[M];
  int vis[M];
  void init() {
    create(0);
    lst = 0;
  }
  int create(int id = 0) {
    memset(ch[id], 0, sizeof(ch[0]));
    len[id] = link[id] = cntPos[id] = 0;
    ;
    return sz = id;
  }
  void extend(const char *s) {
    for (int i = 0; s[i]; ++i) {
      int c = s[i] - 'a';
      int cur = create(sz + 1);
      len[cur] = len[lst] + 1;
      int p = lst;
      while (ch[p][c] == 0) {
        ch[p][c] = cur;
        p = link[p];
      }
      if (ch[p][c] != cur) {
        int q = ch[p][c];
        if (len[p] + 1 == len[q]) {
          link[cur] = q;
        } else {
          int clone = create(sz + 1);
          memcpy(ch[clone], ch[q], sizeof(ch[q]));
          link[clone] = link[q];
          len[clone] = len[p] + 1;
          while (ch[p][c] == q) {
            ch[p][c] = clone;
            p = link[p];
          }
          link[q] = link[cur] = clone;
        }
      }
      lst = cur;
      ++cntPos[cur];
    }
  }
  void build() {
    vector<int> nodes;
    for (int i = 1; i <= sz; ++i) nodes.push_back(i);
    sort(nodes.begin(), nodes.end(),
         [&](int a, int b) { return len[a] > len[b]; });
    for (auto u : nodes) {
      int v = link[u];
      cntPos[v] += cntPos[u];
    }
  }
  int query(char *s, int n, int ver) {
    int ans = 0, x = 0, now = 0;
    for (int i = 0; s[i]; ++i) {
      int c = s[i] - 'a';
      while (x && ch[x][c] == 0) {
        x = link[x];
        now = len[x];
      }
      if (ch[x][c]) {
        x = ch[x][c];
        ++now;
      }
      while (x && len[link[x]] >= n) x = link[x];
      if (now >= n && vis[x] != ver) {
        ans += cntPos[x];
        vis[x] = ver;
      }
    }
    return ans;
  }
} SAM;
char s[1000010], t[2000010];
int main() {
  int n, m;
  int q;
  scanf("%s", s);
  SAM.extend(s);
  SAM.build();
  scanf("%d", &q);
  for (int fk = 1; fk <= q; ++fk) {
    scanf("%s", t);
    n = strlen(t);
    for (int i = 0; i < n; ++i) t[i + n] = t[i];
    t[2 * n] = '\0';
    printf("%d\n", SAM.query(t, n, fk));
  }
  return 0;
}