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;
struct SAM {
  struct node {
    int ch[26];
    int link;
    int len;
    int cnt;
    int vis;
  } t[2000000 + 5];
  vector<int> E[2000000 + 5];
  const int root = 1;
  int ptr = 1;
  int last = root;
  void extend(int c) {
    int p = last, cur = ++ptr;
    (t[cur].len) = (t[p].len) + 1;
    t[cur].cnt = 1;
    while (p && t[p].ch[c] == 0) {
      t[p].ch[c] = cur;
      p = (t[p].link);
    }
    if (p == 0)
      (t[cur].link) = root;
    else {
      int q = t[p].ch[c];
      if ((t[p].len) + 1 == (t[q].len))
        (t[cur].link) = q;
      else {
        int clo = ++ptr;
        (t[clo].link) = (t[q].link);
        memcpy(t[clo].ch, t[q].ch, sizeof(t[q].ch));
        (t[clo].len) = (t[p].len) + 1;
        (t[cur].link) = (t[q].link) = clo;
        while (p && t[p].ch[c] == q) {
          t[p].ch[c] = clo;
          p = (t[p].link);
        }
      }
    }
    last = cur;
  }
  void dfs(int x) {
    for (int i = 0; i < (int)E[x].size(); i++) {
      int y = E[x][i];
      dfs(y);
      t[x].cnt += t[y].cnt;
    }
  }
  void build(char *s) {
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++) extend(s[i] - 'a');
    for (int i = 2; i <= ptr; i++) E[(t[i].link)].push_back(i);
    dfs(root);
  }
  int query(char *s, int qid) {
    int ans = 0;
    int m = strlen(s + 1);
    int x = 1, len = 0;
    for (int i = 1; i <= m; i++) {
      int c = s[i] - 'a';
      while (x && t[x].ch[c] == 0) {
        x = (t[x].link);
        len = (t[x].len);
      }
      if (t[x].ch[c]) {
        len++;
        x = t[x].ch[c];
      }
    }
    if (len == m && t[x].vis < qid) {
      ans += t[x].cnt;
      t[x].vis = qid;
    }
    for (int i = 1; i <= m; i++) {
      int c = s[i] - 'a';
      while (x && t[x].ch[c] == 0) {
        x = (t[x].link);
        len = (t[x].len);
      }
      if (t[x].ch[c]) {
        len++;
        x = t[x].ch[c];
      }
      if (len > m) {
        len--;
        if (len == (t[(t[x].link)].len)) x = (t[x].link);
      }
      if (len == m && t[x].vis < qid) {
        ans += t[x].cnt;
        t[x].vis = qid;
      }
    }
    return ans;
  }
};
SAM T;
char s[2000000 + 5], t[2000000 + 5];
int q;
int main() {
  scanf("%s", s + 1);
  scanf("%d", &q);
  T.build(s);
  for (int i = 1; i <= q; i++) {
    scanf("%s", t + 1);
    printf("%d\n", T.query(t, i));
  }
}