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.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    int N;
    String S;
    State[] st;
    int idx;
    int last;
    ArrayList<Integer>[] lengths;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        S = in.nextString();
        N = S.length();

        st = new State[2 * N];
        idx = last = 0;
        st[0] = new State();
        st[0].len = 0;
        st[0].link = -1;
        idx++;

        lengths = new ArrayList[N + 1];
        for(int i = 0; i < N + 1; i++)
            lengths[i] = new ArrayList<Integer>();

        for(int i = 0; i < N; i++)
            extend(S.charAt(i));

        st[0].ways = 0;
        for(int i = N; i > 0; i--)
            for(int j : lengths[i])
            st[ st[j].link ].ways += st[j].ways;

        /*for(int i = 0; i < idx; i++) {
            System.out.println("#" + i + ": " + st[i].len + " " + st[i].link + " " + st[i].ways);
            for(int j = 0; j < 26; j++)
                if(st[i].next[j] != -1)
                    System.out.print(st[i].next[j] + "(" + j + ") ");
            System.out.println();
        }*/

        int M = in.nextInt();
        for(int i = 0; i < M; i++) {
            String x = in.nextString();

            int period = getPeriod(x);

//            System.out.println("P: " + period);

            int ans = 0;
            int crtState = 0;
            int crtLen = 0;

            for(int j = 0; j < x.length(); j++) {
                char c = x.charAt(j);

                while(crtState != -1 && st[crtState].next[c - 'a'] == -1) {
                    crtState = st[crtState].link;
                    if(crtState != -1)
                        crtLen = st[crtState].len;
                }

                if(crtState == -1) {
                    crtState = 0;
                    crtLen = 0;
                }
                else {
                    crtState = st[crtState].next[c - 'a'];
                    crtLen++;
                }
            }

            if(crtLen == x.length())
                ans += st[crtState].ways;

            for(int j = 0; j < period - 1; j++) {
                if(crtLen == x.length()) {
                    crtLen--;

                    if(crtLen <= st[ st[crtState].link ].len)
                        crtState = st[crtState].link;
                }

                char c = x.charAt(j);

                while(crtState != -1 && st[crtState].next[c - 'a'] == -1) {
                    crtState = st[crtState].link;
                    if(crtState != -1)
                        crtLen = st[crtState].len;
                }

                if(crtState == -1) {
                    crtState = 0;
                    crtLen = 0;
                }
                else {
                    crtState = st[crtState].next[c - 'a'];
                    crtLen++;
                }

                if(crtLen == x.length())
                    ans += st[crtState].ways;
            }

            out.println(ans);
        }
    }

    private int getPeriod(String s) {
        int n = s.length();
        int[] pr = new int[n];
        pr[0] = -1;
        int k = -1;

        for(int i = 1; i < n; i++) {
            while(k >= 0 && s.charAt(i) != s.charAt(k + 1))
                k = pr[k];

            if(s.charAt(i) == s.charAt(k + 1))
                k++;

            pr[i] = k;
        }

        if(n > 1 && n % (n - pr[n - 1] - 1) == 0)
            return n - pr[n - 1] - 1;
        return n;
    }

    private void extend(char c) {
        int crt = idx++;
        st[crt] = new State();
        st[crt].len = st[last].len + 1;
        lengths[ st[crt].len ].add(crt);

        int p = last;
        for(; p != -1 && st[p].next[c - 'a'] == -1; p = st[p].link)
            st[p].next[c - 'a'] = crt;

        if(p == -1)
            st[crt].link = 0;
        else {
            int q = st[p].next[c - 'a'];
            if(st[p].len + 1 == st[q].len)
                st[crt].link = q;
            else {
                int clone = idx++;
                st[clone] = new State(st[q]);
                st[clone].len = st[p].len + 1;

                lengths[ st[clone].len ].add(clone);

                for(; p != -1 && st[p].next[c - 'a'] == q; p = st[p].link)
                    st[p].next[c - 'a'] = clone;

                st[crt].link = st[q].link = clone;
            }
        }

        last = crt;
    }


    private class State {
        public int len;
        public int link;
        public int[] next;
        public int ways;

        private State() {
            next = new int[26];
            Arrays.fill(next, -1);
            ways = 1;
        }

        private State(State o) {
            len = o.len;
            link = o.link;
            next = new int[26];
            System.arraycopy(o.next, 0, next, 0, 26);
            ways = 0;
        }
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));

        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }