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 M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << '(' << p.first << "," << p.second << ')';
}
const int LEN = 2000005;
struct SA {
  struct state {
    int len, link;
    map<char, int> next;
  };
  state st[LEN];
  int sz, last;
  long long cnt[LEN];
  bitset<LEN> vis;
  void SA_make() {
    sz = 0;
    st[0].len = 0, st[0].link = -1;
    ++sz;
    last = 0;
  }
  SA() { SA_make(); }
  void add(char c) {
    int new_n = sz++;
    st[new_n].len = st[last].len + 1;
    int pt = last;
    while (pt != -1 && !st[pt].next.count(c)) {
      st[pt].next[c] = new_n;
      pt = st[pt].link;
    }
    if (pt == -1) {
      st[new_n].link = 0;
    } else {
      int q_st = st[pt].next[c];
      if (st[q_st].len == st[pt].len + 1)
        st[new_n].link = q_st;
      else {
        int clone = sz++;
        st[clone] = st[q_st];
        st[clone].len = st[pt].len + 1;
        st[q_st].link = st[new_n].link = clone;
        while (pt != -1 && st[pt].next[c] == q_st) {
          st[pt].next[c] = clone;
          pt = st[pt].link;
        }
      }
    }
    last = new_n;
  }
  void count() {
    vector<int> v;
    for (int i = 1; i < sz; ++i) v.push_back(i);
    sort(v.begin(), v.end(),
         [&](int x, int y) { return st[x].len > st[y].len; });
    for (int i = 0; i < sz - 1; ++i) {
      cnt[st[v[i]].link] += cnt[v[i]];
    }
  }
  int minlen(int u) {
    if (u == 0) return 0;
    return st[st[u].link].len + 1;
  }
  void build(string &s) {
    for (char c : s) {
      add(c);
      ++cnt[last];
    }
    count();
  }
  long long query(string &t, int len) {
    vector<int> del;
    long long ans = 0;
    int cur_state = 0;
    int l = 0, r = -1;
    while (l < len && r < (long long)t.size()) {
      if (r - l + 1 == len) {
        if (!vis[cur_state])
          ans += cnt[cur_state], vis[cur_state] = 1, del.push_back(cur_state);
        int u = minlen(cur_state);
        if (u == len) {
          cur_state = st[cur_state].link;
        }
        ++l;
      } else {
        if (st[cur_state].next.count(t[r + 1]))
          cur_state = st[cur_state].next[t[r + 1]], ++r;
        else {
          int u = minlen(cur_state);
          if (u == r - l + 1) cur_state = st[cur_state].link;
          ++l;
          if (r < l - 1) ++r;
        }
      }
    }
    for (auto j : del) vis[j] = 0;
    return ans;
  }
  void go(string t = "aabb") {
    int cur = 0;
    cout << st[0].next['a'];
    for (int i = 0; i < 4; ++i) {
      if (st[cur].next.count(t[i])) {
        cur = st[cur].next[t[i]];
        cout << cur << "\n";
      }
    }
  }
} sa;
int _runtimeTerror_() {
  string s;
  cin >> s;
  sa.build(s);
  int n = (long long)s.size();
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    string t;
    cin >> t;
    t += t;
    t.pop_back();
    cout << sa.query(t, ((long long)t.size() + 1) / 2) << "\n";
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) _runtimeTerror_();
  return 0;
}