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.util.List;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

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

class TaskC {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
        String S = in.next();
        int n = in.nextInt();


        StringUtils.SuffixAutomata sa  = new StringUtils.SuffixAutomata('a','z');
        for(char c : S.toCharArray()) sa.addChar(c);
        sa.recalcSizes();
        
        
        int i,j,k;
        for(i=0;i<n;++i){
            String x = in.next();
            int m = x.length();
            x+=x;
            char c[] = x.toCharArray();
            
            int z[] = StringUtils.zFunction(c);
            for(j=1;j<m;++j) if(z[j]>=m) break;
            int end = j;

            long ans = 0;
            StringUtils.SuffixAutomata.State t = sa.nil, q;
            int len = 0;
            for(k=0;k<c.length;++k) if(k-m+1<end){
                while(t!=null && t.to[c[k]-'a']==sa.nil) t = t.link;
                if(t==null){
                    t = sa.nil;
                    len = 0;
                }else{
                    len = Math.min(len, t.length);
                    t = t.to[c[k]-'a'];
                    ++len;
                }
                if(k-m+1>=0 && len>=m){
                    q = t;
                    while(q!=null && q.length>=m && q.link.length>=m) q = q.link;
                    if(q==null) q = sa.nil;
                    if(q.length>=m) {ans+=q.size;
                    }
                    t = q;
                }
            }

            

            out.writeln(ans);
        }
	}
    
    }

class InputReader{
    private InputStream in;
    private byte buffer[] = new byte[1<<11];
    private int cur;
    private int end;
    
    
    public InputReader(InputStream stream){
        in = stream;
    }
    
    public int read(){
        if(end<0) throw new InputMismatchException();
        if(cur>=end){
            cur = 0;
            try{
                end = in.read(buffer);
            }catch(IOException e){
                throw new InputMismatchException();
            }
            if(end<=0) return -1;
        }
        return buffer[cur++];
    }
    
    public boolean isSpace(int c){
        return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
    }
    
    public String next(){
        StringBuilder s = new StringBuilder();
        int c = read();
        while(isSpace(c)) c = read();
        do{
            s.append((char)c);
            c = read();
        }while(!isSpace(c));
        return s.toString();
    }
    
    public int nextInt(){
        int c = read(), res = 0, sign = 1;
        while(isSpace(c)) c = read();
        if(c=='-'){ sign = -1; c = read(); }
        do{
            if(c>'9' || c<'0') throw new InputMismatchException();
            res = res*10 + (c-'0');
            c = read();
        }while(!isSpace(c));
        return res*sign;
    }

    }

class OutputWriter{
    private PrintWriter out;
    
    public OutputWriter(Writer out){
        this.out = new PrintWriter(out);
    }

    public OutputWriter(OutputStream out){
        this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
    }
    
    public void close(){
        out.close();
    }

    public void write(Object ... o){
        for(Object x : o) out.print(x);
    }
    
    public void writeln(Object ... o){
        write(o);
        out.println();
    }
}

class StringUtils{
    
    public static int[] zFunction(char s[]){
        int n = s.length, i, j;
        int z[] = new int[n];
        z[0] = j = 0;
        for(i=1; i<n; ++i){
            int k = Math.max(0, Math.min(z[i-j], j+z[j]-i));
            while(i+k<n && s[k]==s[i+k]) ++k;
            if(i+k > j+z[j]) j = i;
            z[i] = k;
        }
        return z;
    }
    
    
    
    
    
    
    
    public static class SuffixAutomata{
        public char smallestChar = 'a';
        public char greatestChar = 'z';
        public ArrayList<State> all;
        
        public static class State{
            int length;
            State link;
            State to[];
            int size;
            
            public State(){}
        }
        
        State nil, last;
        
        public SuffixAutomata(char fromChar, char toChar){
            smallestChar = fromChar;
            greatestChar = toChar;
            nil = new State();
            nil.length = 0;
            nil.link = null;
            nil.to = new State[greatestChar-smallestChar+1];
            Arrays.fill(nil.to, nil);
            last = nil;
            all  = new ArrayList<State>();
            all.add(nil);
        }
        
        public void addChar(char c){
            c -= smallestChar;
            State current = new State();
            current.size = 1;
            current.length = last.length+1;
            current.link = nil;
            current.to = new State[greatestChar-smallestChar+1];
            all.add(current);
            Arrays.fill(current.to, nil);
            for(; last!=null && last.to[c]==nil; last = last.link) last.to[c] = current;
            if(last!=null){
                State p = last.to[c];
                if(p.length==last.length+1) current.link = p; else{
                    State q = new State();
                    q.size = 0;
                    q.length = last.length+1;
                    q.link = p.link;
                    q.to = p.to.clone();
                    all.add(q);
                    for(; last!=null && last.to[c]==p; last = last.link) last.to[c] = q;
                    p.link = current.link = q;
                }
            }
            last = current;
        }
        
        public void recalcSizes(){
            Collections.sort(all, new Comparator<State>() {
                public int compare(State o1, State o2) {
                    return o2.length-o1.length;
                }
            });
            
            for(State st : all) if(st.link!=null) st.link.size+=st.size;
        }
        
        }

    
    }