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;
inline int cti(char x) { return x - 'a'; }
typedef class TrieNode {
 public:
  TrieNode* next[26];
  TrieNode* fail;
  vector<TrieNode*> son;
  int cnt;
  int len;
  int t;
  TrieNode() : fail(NULL), cnt(0), len(0), t(2333333) {
    memset(next, 0, sizeof(next));
  }
} TrieNode;
typedef class SuffixAutomachine {
 public:
  TrieNode* pool;
  TrieNode* top;
  TrieNode* root;
  TrieNode* last;
  TrieNode* newnode() { return top++; }
  TrieNode* newnode(int len) {
    top->len = len;
    return top++;
  }
  SuffixAutomachine() : pool(NULL), top(NULL), root(NULL), last(NULL) {}
  SuffixAutomachine(int len) {
    pool = new TrieNode[len * 2 + 5];
    top = pool;
    root = newnode();
    last = root;
  }
  inline void extend(char x) {
    int c = cti(x);
    TrieNode *node = newnode(last->len + 1), *f = last;
    node->cnt = 1;
    while (f && f->next[c] == NULL) f->next[c] = node, f = f->fail;
    if (f == NULL)
      node->fail = root;
    else {
      TrieNode* p = f->next[c];
      if (p->len == f->len + 1)
        node->fail = p;
      else {
        TrieNode* clone = newnode(f->len + 1);
        memcpy(clone->next, p->next, sizeof(clone->next));
        clone->fail = p->fail;
        p->fail = clone;
        node->fail = clone;
        while (f && f->next[c] == p) f->next[c] = clone, f = f->fail;
      }
    }
    last = last->next[c];
  }
} SuffixAutomachine;
int lens;
int n;
char str[2000005];
SuffixAutomachine sam;
inline void init() {
  gets(str);
  lens = strlen(str);
}
int dfs(TrieNode* p) {
  for (int i = 0; i < (signed)p->son.size(); i++) p->cnt += dfs(p->son[i]);
  return p->cnt;
}
inline void init_sam() {
  sam = SuffixAutomachine(lens);
  for (int i = 0; i < lens; i++) sam.extend(str[i]);
  for (TrieNode* p = sam.pool; p != sam.top; p++) {
    if (p->fail) p->fail->son.push_back(p);
  }
  dfs(sam.root);
}
inline void solve() {
  scanf("%d", &n);
  gets(str);
  while (n--) {
    gets(str);
    lens = strlen(str);
    memcpy(str + lens, str, sizeof(char) * (lens - 1));
    TrieNode *p = sam.root, *q;
    int res = 0;
    for (int i = 0, nlen = 0, c; i < 2 * lens - 1 && p; i++) {
      c = cti(str[i]);
      if (!p->next[c]) {
        while (p && !p->next[c]) p = p->fail, nlen = (p) ? (p->len) : (0);
        if (!p) break;
      }
      p = p->next[c], nlen++;
      if (nlen >= lens) {
        q = p;
        while (q->fail->len >= lens) q = q->fail;
        if (q->t != n) {
          res += q->cnt;
          q->t = n;
        }
      }
    }
    printf("%d\n", res);
  }
}
int main() {
  init();
  init_sam();
  solve();
  return 0;
}