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:
//package round146;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class C2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
//	String INPUT = "abbabbabba\r\n" + 
//			"5\r\n" + 
//			"ab\r\n" + 
//			"bba\r\n" + 
//			"bbab\r\n" + 
//			"b\r\n" + 
//			"bbabb";
//	String INPUT = "aabbaa 3 aa aabb abba";
//	String INPUT = "baabaabaaa\r\n" + 
//			"5\r\n" + 
//			"a\r\n" + 
//			"ba\r\n" + 
//			"baa\r\n" + 
//			"aabaa\r\n" + 
//			"aaba";
	
	void solve()
	{
		char[] str = ns().toCharArray();
		SAState[] sa = buildSuffixAutomaton(str);
		int[] ct = enumNumberOfOccurs(sa);
		
		int[] poss = new int[1000001];
		int Q = ni();
		for(int i = 0;i < Q;i++){
			char[] q = ns().toCharArray();
			SAState cur = sa[0];
			int m = q.length;
			int pp = 0;
			int l = 0;
			for(int j = 0;j < 2*m-1;j++){
				int e = enc(q[j%m]);
				while(cur != sa[0] && cur.next[e] == null){
					cur = cur.link;
					l = cur.len;
				}
				if(cur.next[e] != null){
					cur = cur.next[e];
					l++;
				}
				while(l >= m && cur.link.len >= m){
					cur = cur.link;
					l = cur.len;
				}
				if(l >= m){
					poss[pp++] = cur.index;
				}
			}
			Arrays.sort(poss, 0, pp);
			long ret = 0;
			for(int j = 0;j < pp;j++){
				if(j == 0 || poss[j] != poss[j-1]){
					ret += ct[poss[j]];
				}
			}
			out.println(ret);
		}
	}
	
	public static SAState[] buildSuffixAutomaton(char[] a) {
		int n = a.length;
		SAState[] st = new SAState[2*n];
		st[0] = new SAState();
		st[0].len = 0;
		st[0].link = null;
		st[0].index = 0;
		
		SAState last = st[0];
		int sz = 1;
		
		// extend
		for(char c : a){
			int v = enc(c);
			int cur = sz++;
			st[cur] = new SAState();
			st[cur].index = -cur;
			st[cur].len = last.len + 1;
			SAState p;
			for(p = last; p != null && p.next[v] == null; p = p.link){
				p.next[v] = st[cur];
			}
			if(p == null){
				st[cur].link = st[0];
			}else{
				SAState q = p.next[v];
				if(p.len + 1 == q.len){
					st[cur].link = q;
				}else{
					int clone = sz++;
					st[clone] = new SAState();
					st[clone].index = -clone;
					st[clone].original = q.original != null ? q.original : q;
					st[clone].len = p.len+1;
					st[clone].next = Arrays.copyOf(q.next, q.next.length);
					st[clone].link = q.link;
					for(;p != null && p.next[v] == q;p = p.link){
						p.next[v] = st[clone];
					}
					q.link = st[cur].link = st[clone];
				}
			}
			last = st[cur];
		}
		
		// topological sort
		int[] nct = new int[sz];
		for(int i = 0;i < sz;i++){
			for(SAState e : st[i].next){
				if(e != null){
					nct[-e.index]++;
				}
			}
		}
		
		SAState[] ret = new SAState[sz];
		int p = 1;
		ret[0] = st[0];
		ret[0].index = 0;
		for(int r = 0;r < p;r++){
			for(SAState e : ret[r].next){
				if(e != null && --nct[-e.index] == 0){
					e.index = p;
					ret[p++] = e;
				}
			}
		}
		return ret;
	}
	
	public static int[] enumNumberOfOccurs(SAState[] sa)
	{
		int n = sa.length;
		int[] dp = new int[n];
		for(int i = n-1;i >= 1;i--){
			if(sa[i].original == null)dp[i] += 1;
			dp[sa[i].link.index] += dp[i];
		}
		return dp;
	}
	
	public static SAState track(char[] str, SAState[] sa)
	{
		SAState cur = sa[0];
		for(int i = 0;i < str.length;i++){
			SAState nex = cur.next[enc(str[i])];
			if(nex == null)return null;
			cur = nex;
		}
		return cur;
	}
	
	public static int enc(char c) { return c - 'a'; }
	public static char dec(int n) { return (char)('a'+n); }
	
	public static class SAState {
		public int index; // 配列上のindex
		public int len;// initialからの最短経路長
		public SAState link; // Failure Link
		public SAState[] next; // つぎ
		public SAState original; // clonedの場合original
		
		public SAState() {
			next = new SAState[26];
			this.index = -1;
		}
		
		public String toString()
		{
			StringBuilder sb = new StringBuilder();
			sb.append("{");
			sb.append("index:").append(index).append(", ");
			if(original != null)sb.append("original:").append(original.index).append(", ");
			sb.append("len:").append(len).append(", ");
			if(index != 0)sb.append("link:").append(link.index).append(", ");
			sb.append("next:{");
			for(int i = 0;i < 26;i++){
				if(next[i] != null){
					sb.append(dec(i)).append(":").append(next[i].index).append(",");
				}
			}
			sb.append("}}\n");
			return sb.toString();
		}
	}
	
	void run() throws Exception
	{
//		int n = 1000000, m = 99999;
//		Random gen = new Random();
//		StringBuilder sb = new StringBuilder();
//		for(int i = 0;i < n;i++){
//			sb.append((char)('a'+gen.nextInt(3)));
//		}
//		sb.append("\n");
//		sb.append(m + " ");
//		for(int i = 0;i < m;i++){
//			for(int j = 0;j < 10;j++){
//				sb.append((char)('a'+gen.nextInt(3)));
//			}
//			sb.append("\n");
//		}
//		INPUT = sb.toString();
		
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void main(String[] args) throws Exception
	{
		new C2().run();
	}
	
	public int ni()
	{
		try {
			int num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}
			
			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}
	
	public long nl()
	{
		try {
			long num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}
			
			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}
	
	public String ns()
	{
		try{
			int b = 0;
			StringBuilder sb = new StringBuilder();
			while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
			if(b == -1)return "";
			sb.append((char)b);
			while(true){
				b = is.read();
				if(b == -1)return sb.toString();
				if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
				sb.append((char)b);
			}
		} catch (IOException e) {
		}
		return "";
	}
	
	public char[] ns(int n)
	{
		char[] buf = new char[n];
		try{
			int b = 0, p = 0;
			while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
			if(b == -1)return null;
			buf[p++] = (char)b;
			while(p < n){
				b = is.read();
				if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
				buf[p++] = (char)b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}
	
	
	double nd() { return Double.parseDouble(ns()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}