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 N = 1000006, SZ = 26;
char ss[N], t[N + N];
int Q;
class SuffixAutomaton {
 public:
  struct state {
    int len, link, nxt[SZ];
    bool is_cloned;
    state() {
      len = 0;
      link = -1;
      is_cloned = false;
      memset(nxt, -1, sizeof nxt);
    }
  };
  string s;
  int n, last, sz;
  vector<state> st;
  vector<bool> terminal;
  SuffixAutomaton() {}
  void init(string sss) {
    s = sss;
    n = s.size();
    st.clear();
    terminal.clear();
    st.resize(n + n);
    terminal.resize(n + n, 0);
    last = 0;
    sz = 1;
    build();
  }
  void extend(char cc) {
    int c = cc - 'a';
    int cur = sz++;
    st[cur].len = st[last].len + 1;
    int p = last;
    while (p != -1 && st[p].nxt[c] == -1) {
      st[p].nxt[c] = cur;
      p = st[p].link;
    }
    if (p == -1) {
      st[cur].link = 0;
    } else {
      int q = st[p].nxt[c];
      if (st[p].len + 1 == st[q].len) {
        st[cur].link = q;
      } else {
        int clone = sz++;
        st[clone].is_cloned = true;
        st[clone].len = st[p].len + 1;
        for (int i = 0; i < SZ; i++) {
          st[clone].nxt[i] = st[q].nxt[i];
        }
        st[clone].link = st[q].link;
        st[q].link = st[cur].link = clone;
        while (p != -1 && st[p].nxt[c] == q) {
          st[p].nxt[c] = clone;
          p = st[p].link;
        }
      }
    }
    last = cur;
  }
  void getTerminal() {
    int p = last;
    while (p != -1) {
      terminal[p] = true;
      p = st[p].link;
    }
  }
  void build() {
    for (int i = 0; i < n; i++) {
      extend(s[i]);
    }
    getTerminal();
  }
  vector<int> dp, vis;
  int rec(int x) {
    if (dp[x] != -1) return dp[x];
    dp[x] = 0;
    for (int i = 0; i < SZ; i++) {
      if (st[x].nxt[i] == -1) continue;
      dp[x] += rec(st[x].nxt[i]);
    }
    dp[x] += terminal[x];
    return dp[x];
  }
  long long go(int m) {
    long long res = 0;
    int x = 0, i = 0, ln = 0;
    while (i < m + m - 1) {
      while (x != -1 && st[x].nxt[t[i] - 'a'] == -1) {
        x = st[x].link;
        if (x != -1) {
          ln = st[x].len;
        }
      }
      if (x != -1) {
        x = st[x].nxt[t[i] - 'a'];
        ln++;
      } else {
        x = ln = 0;
      }
      if (ln == m) {
        if (vis[x] != Q) {
          res += dp[x];
          vis[x] = Q;
        }
        if (ln == st[st[x].link].len + 1) {
          x = st[x].link;
          ln = st[x].len;
        } else {
          ln--;
        }
      }
      i++;
    }
    return res;
  }
  void calc() {
    dp.clear();
    dp.resize(n + n, -1);
    vis.clear();
    vis.resize(n + n, -1);
    rec(0);
  }
  void print() {
    for (int i = 0; i < sz; i++) {
      printf("%d: link: %d len: %d %d %d\n", i, st[i].link, st[i].len,
             (int)terminal[i], dp[i]);
      for (int j = 0; j < SZ; j++) {
        if (st[i].nxt[j] != -1) {
          printf("%c %d\n", 'a' + j, st[i].nxt[j]);
        }
      }
    }
  }
};
int main() {
  scanf("%s", ss);
  string s = "";
  for (int i = 0; ss[i]; i++) {
    s += ss[i];
  }
  SuffixAutomaton SA;
  SA.init(s);
  SA.calc();
  int q;
  scanf("%d", &q);
  for (Q = 0; Q < q; Q++) {
    scanf("%s", t);
    int m = strlen(t);
    for (int i = m; i < m + m - 1; i++) {
      t[i] = t[i - m];
    }
    t[m + m - 1] = '\0';
    printf("%lld\n", SA.go(m));
  }
  return 0;
}