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 JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class CF235C {
    static String text;
    static String pattern;

    public static void main(String[] args) {
        text = IN.next();
        init();
        extend();
        topoSort();
        int n = IN.nextInt(), i = 1;
        vis = new int[id];
        while (n-- > 0) {
            pattern = IN.next();
            solve(i++);
        }
        System.out.print(sb.toString());
    }

    static StringBuilder sb = new StringBuilder(65535);
    static int curState;
    static int curLen;
    static int count;
    static int vis[];

    public static void solve(int nth) {
        curState = 0;
        curLen = 0;
        count = 0;
        for (int i = 0; i < pattern.length(); i++) {
            if (!work(i, nth)) {
                break;
            }
        }
        sb.append(count).append('\n');
    }

    private static boolean work(int start, int nth) {
        if (curState != 0) {
            curLen--;
            if (curLen <= len[next[curState]]) {
                curState = next[curState];
            }
        }
        int plen = pattern.length(), i = (start + curLen) % plen;
        while (curLen != plen) {
            int c = pattern.charAt(i++) - 'a';
            i %= plen;
            if (child[c][curState] == 0) {
                break;
            } else {
                curState = child[c][curState];
                curLen++;
            }
        }
        if (curLen != plen) {
            return true;
        }
        if (vis[curState] == nth) {
            return false;
        } else {
            vis[curState] = nth;
            count += size[curState];
            return true;
        }
    }

    static int child[][];
    static int next[];
    static int len[];
    static int size[];
    static int id;

    public static void init() {
        int n = text.length();
        child = new int[26][n << 1];
        next = new int[n << 1];
        len = new int[n << 1];
        size = new int[n << 1];
        id = 1;
        next[0] = -1;
    }

    public static void extend() {
        int pre = 0, j = -1, cur = -1;
        for (int i = 0; i < text.length(); i++) {
            int c = text.charAt(i) - 'a';
            cur = id++;
            len[cur] = len[pre] + 1;
            j = pre;
            pre = cur;
            size[cur] = 1;
            while (j != -1 && child[c][j] == 0) {
                child[c][j] = cur;
                j = next[j];
            }
            if (j != -1) {
                int k = child[c][j];
                if (len[j] + 1 == len[k]) {
                    next[cur] = k;
                } else {
                    int nk = id++;
                    len[nk] = len[j] + 1;
                    next[nk] = next[k];
                    for (int a = 0; a < 26; a++) {
                        child[a][nk] = child[a][k];
                    }
                    next[k] = nk;
                    next[cur] = nk;
                    while (j != -1 && child[c][j] == k) {
                        child[c][j] = nk;
                        j = next[j];
                    }
                }
            }
        }
    }

    public static void topoSort() {
        int cntLen[] = new int[text.length() + 1];
        for (int i = 0; i < id; i++) {
            cntLen[len[i]]++;
        }
        for (int i = 1; i < cntLen.length; i++) {
            cntLen[i] += cntLen[i - 1];
        }
        int sorted[] = new int[id];
        for (int i = id - 1; i >= 0; i--) {
            sorted[--cntLen[len[i]]] = i;
        }
        for (int i = id - 1; i > 0; i--) {
            int cur = sorted[i];
            size[next[cur]] += size[cur];
        }
    }

    static class IN {

        private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 65535);
        private static StringTokenizer st = null;

        public static String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    break;
                }
            }
            return st.nextToken();
        }

        public static int nextInt() {
            return Integer.valueOf(next());
        }

        public static long nextLong() {
            return Long.valueOf(next());
        }

        public static void close() {
            try {
                br.close();
            } catch (IOException e) {
            }
        }
    }
}