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 debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << "\t";
    return *this;
  }
} dbg;
template <class T>
void setmax(T& a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
T Abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T Mod(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
string toString(T n) {
  ostringstream oss;
  oss << n;
  oss.flush();
  return oss.str();
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
bool isVowel(char ch) {
  ch = tolower(ch);
  if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
    return true;
  return false;
}
bool isUpper(char c) { return c >= 'A' && c <= 'Z'; }
bool isLower(char c) { return c >= 'a' && c <= 'z'; }
long long Pow(long long B, long long P) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) R = (R * B);
    P /= 2;
    B = (B * B);
  }
  return R;
}
int BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return (int)R;
}
void binprint(long long mask, long long n) {
  long long i;
  string s = "";
  do {
    s += (mask % 2 + '0');
    mask /= 2;
  } while (mask);
  reverse(s.begin(), s.end());
  s = string(max(n - (int)s.size(), 0LL), '0') + s;
  for (i = (int)s.size() - n; i < (int)s.size(); i++) printf("%c", s[i]);
  printf("\n");
}
void ASCII_Chart() {
  int i, j, k;
  printf("ASCII Chart:(30-129)\n");
  for (i = 30; i < 50; i++) {
    for (j = 0; j < 5; j++) {
      k = i + j * 20;
      printf("%3d---> '%c'   ", k, k);
    }
    printf("\n");
  }
}
struct state {
  int link, len, freq;
  int child[26];
};
state T[2 * 1001000];
int sz, last;
void initialize(int N) {
  sz = 1;
  last = 0;
  for (int i = 0; i < N; i++) {
    T[i].link = -1;
    T[i].len = 0;
    memset(T[i].child, 0, sizeof(T[i].child));
  }
}
void add_char(char ch) {
  int cur = sz++;
  T[cur].len = T[last].len + 1;
  T[cur].freq = 1;
  int p;
  for (p = last; p != -1 && T[p].child[ch] == 0; p = T[p].link)
    T[p].child[ch] = cur;
  if (p == -1)
    T[cur].link = 0;
  else {
    int q = T[p].child[ch];
    if (T[p].len + 1 == T[q].len)
      T[cur].link = q;
    else {
      int clone = sz++;
      T[clone].link = T[q].link;
      T[clone].len = T[p].len + 1;
      T[clone].freq = 0;
      memcpy(T[clone].child, T[q].child, sizeof T[q].child);
      for (p = p; p != -1 && T[p].child[ch] == q; p = T[p].link)
        T[p].child[ch] = clone;
      T[cur].link = T[q].link = clone;
    }
  }
  last = cur;
}
char str[1001000];
vector<int> adj[1001000];
int Len;
void build_automata() {
  int i, j, u, v;
  initialize(Len * 2);
  for (i = 0; i < Len; i++) add_char(str[i] - 'a');
  for (i = 1; i <= Len; i++) adj[i].clear();
  for (i = 1; i < sz; i++) {
    adj[T[i].len].push_back(i);
  }
  for (i = Len; i > 0; i--) {
    for (j = 0; j < (int)adj[i].size(); j++) {
      u = adj[i][j];
      v = T[u].link;
      T[v].freq += T[u].freq;
    }
  }
}
int flag[2 * 1001000], Case;
long long find_cyclic_occurrance(string s) {
  int reqLen = (int)s.size();
  s = s + s;
  int cur, len;
  cur = 0;
  len = 0;
  flag[0] = Case;
  long long ret = 0;
  for (int ind = 0; ind < (int)s.size(); ind++) {
    char ch = s[ind] - 'a';
    if (T[cur].child[ch]) {
      cur = T[cur].child[ch];
      len++;
      if (len == reqLen) {
        if (flag[cur] != Case) ret += T[cur].freq;
        flag[cur] = Case;
        len--;
        if (T[T[cur].link].len == len) {
          cur = T[cur].link;
        }
      }
    } else {
      int p = T[cur].link;
      for (; p != -1 && T[p].child[ch] == 0; p = T[p].link)
        ;
      if (p == -1) {
        cur = len = 0;
      } else {
        cur = p;
        len = T[p].len;
        ind--;
      }
    }
  }
  return ret;
}
int main() {
  int i, j, test, N;
  while (scanf("%s", str) == 1) {
    Len = strlen(str);
    build_automata();
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
      Case = i + 1;
      scanf("%s", str);
      long long ans = find_cyclic_occurrance(str);
      printf("%I64d\n", ans);
    }
  }
  return 0;
}