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 Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct SAM {
  struct State {
    int to[26];
    int fa, len;
  };
  vector<State> t;
  int lst;
  void inline init() {
    t.clear();
    t.push_back(State());
    t.push_back(State());
    lst = 1;
    t[1].fa = t[1].len = 0;
  }
  SAM() { init(); }
  int inline size() { return ((int)(t).size()) - 1; }
  State inline &operator[](int x) { return t[x]; }
  int inline newnode() {
    t.push_back(State());
    return ((int)(t).size()) - 1;
  }
  int inline add(int p, int c) {
    int np = newnode();
    t[np].len = t[p].len + 1;
    while (p && !t[p].to[c]) {
      t[p].to[c] = np;
      p = t[p].fa;
    }
    if (!p) {
      t[np].fa = 1;
    } else {
      int q = t[p].to[c];
      if (t[p].len + 1 == t[q].len) {
        t[np].fa = q;
      } else {
        int nq = newnode();
        t[nq] = t[q];
        t[nq].len = t[p].len + 1;
        t[q].fa = t[np].fa = nq;
        while (p && t[p].to[c] == q) {
          t[p].to[c] = nq;
          p = t[p].fa;
        }
      }
    }
    return lst = np;
  }
  int inline add(int c) { return add(lst, c); }
} sam;
char s[1 << 20];
int n, m, k, p;
char t[1 << 17];
vector<int> nei[1 << 21];
int cn[1 << 21];
int ep[1 << 21];
void inline dfs(int now) {
  for (int i = 0; i < (((int)(nei[now]).size())); ++i) {
    int to = nei[now][i];
    dfs(to);
    cn[now] += cn[to];
    ep[now] = ep[to];
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  sam.init();
  for (int i = 1; i <= (n); ++i) {
    int pos = sam.add(s[i] - 'a');
    cn[pos] = 1;
    ep[pos] = i;
  }
  p = ((int)(sam).size());
  for (int i = 1; i <= (p); ++i) nei[sam[i].fa].push_back(i);
  dfs(1);
  scanf("%d", &m);
  while (m--) {
    scanf("%s", t);
    int now = 1;
    k = strlen(t);
    int len = 0;
    for (int i = 0; i < (k); ++i) {
      while (now && !sam[now].to[t[i] - 'a'])
        now = sam[now].fa, len = sam[now].len;
      if (!now)
        now = 1, len = 0;
      else
        now = sam[now].to[t[i] - 'a'], ++len;
    }
    set<int> lgl;
    long long ans = 0;
    for (int i = 0; i < (k); ++i) {
      if (i) {
        if (sam[sam[now].fa].len == k - 1) {
          now = sam[now].fa;
        }
        len = min(len, k - 1);
        while (now && !sam[now].to[t[i - 1] - 'a'])
          now = sam[now].fa, len = sam[now].len;
        if (!now)
          now = 1, len = 0;
        else
          now = sam[now].to[t[i - 1] - 'a'], ++len;
      }
      if (len == k) {
        if (lgl.count(now)) continue;
        lgl.insert(now);
        ans += cn[now];
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}