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;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
}
const int inf = 1e9;
const int maxn = 4 * 1e6 + 5;
char s[maxn];
unordered_map<int, int> to[maxn];
int len[maxn], fipos[maxn], link[maxn];
int depth[maxn];
int node, pos;
int sz = 1, n = 0;
int remain = 0;
int make_node(int _pos, int _len) {
  fipos[sz] = _pos;
  len[sz] = _len;
  return sz++;
}
void go_edge(int &node, int &pos) {
  while (pos > len[to[node][s[n - pos]]]) {
    node = to[node][s[n - pos]];
    pos -= len[node];
  }
}
void add_letter(int c) {
  s[n++] = c;
  pos++;
  int last = 0;
  remain++;
  while (pos > 0) {
    go_edge(node, pos);
    int edge = s[n - pos];
    int &v = to[node][edge];
    int t = s[fipos[v] + pos - 1];
    if (v == 0) {
      remain--;
      v = make_node(n - pos, inf);
      link[last] = node;
      last = 0;
    } else if (t == c) {
      link[last] = node;
      return;
    } else {
      remain--;
      int u = make_node(fipos[v], pos - 1);
      to[u][c] = make_node(n - 1, inf);
      to[u][t] = v;
      fipos[v] += pos - 1;
      len[v] -= pos - 1;
      v = u;
      link[last] = u;
      last = u;
    }
    if (node == 0)
      pos--;
    else
      node = link[node];
  }
}
int val[maxn];
int slen;
void dfs(int u, int d = 0) {
  val[u] = (len[u] > slen + 2) && (u != 0);
  depth[u] = min(inf, d);
  for (auto it : to[u]) {
    int v = it.second;
    if (v) {
      dfs(v, d + len[v]);
      val[u] += val[v];
    }
  }
}
void fix(int &node, int &edg, int &pos, int &st, int &en, string &s) {
  int fichar = s[st + depth[node]];
  edg = to[node][fichar];
  while (edg && pos > len[edg]) {
    node = edg;
    pos -= len[edg];
    fichar = s[st + depth[node]];
    edg = to[node][fichar];
  }
}
int main(int argc, char *argv[]) {
  io();
  len[0] = inf;
  string s;
  cin >> s;
  slen = s.length();
  s += '$';
  for (auto c : s) {
    add_letter(c);
  }
  dfs(0);
  int q;
  cin >> q;
  string str;
  while (q--) {
    cin >> str;
    int l = str.length();
    if (l > slen) {
      cout << 0 << '\n';
      continue;
    }
    str = str + str;
    long long ans = 0;
    int st = 0;
    int en = 0;
    int node = 0;
    int edg = 0;
    int pos = 1;
    set<pair<int, pair<int, int>>> done;
    while (st < l) {
      fix(node, edg, pos, st, en, str);
      assert(st <= en);
      if (edg == 0) {
        if (node == 0) {
          pos--;
        } else {
          node = link[node];
        }
        st++;
        if (st > en) {
          en++;
        }
        continue;
      }
      while (en < (st + l)) {
        fix(node, edg, pos, st, en, str);
        int spos = fipos[edg] + pos - 1;
        if (spos >= slen) {
          break;
        }
        if (s[spos] == str[st + depth[node] + pos - 1]) {
          en++;
          pos++;
          fix(node, edg, pos, st, en, str);
        } else {
          break;
        }
      }
      if (en == st + l) {
        if (done.find({node, {edg, pos}}) == done.end()) {
          done.insert({node, {edg, pos}});
          if (pos == 1) {
            ans = ans + val[node];
          } else {
            if (edg != 0) ans = ans + val[edg];
          }
        } else {
        }
      }
      st++;
      if (st > en) {
        en++;
      }
      if (node == 0)
        pos--;
      else
        node = link[node];
    }
    cout << ans << '\n';
  }
  return 0;
}