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.*;
import java.io.*;

public class C235 {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		SuffixAutomaton sa = new SuffixAutomaton(sc.next().toCharArray());
		int q = sc.nextInt();
		while (q-- > 0) {
			pw.println(sa.solve(sc.next().toCharArray()));
		}
		pw.close();

	}

	static class SuffixAutomaton {
		int[] link, len, cnt;
		TreeMap<Character, Integer>[] next;
		int lst, idx;

		public int solve(char[] p) {
			int cur = 0;
			int l = 0;
			HashSet<Integer> hs = new HashSet<Integer>();
			for (int j = 0; j < 2; j++) {
				for (int i = 0; i < p.length; i++) {
//					System.out.println(l + " " + len[link[cur]]);
					while (l > 0 && !next[cur].containsKey(p[i])) {
						l--;
						if (l <= len[link[cur]]) {
							cur = link[cur];
						}
					}
					if (next[cur].containsKey(p[i])) {
						l++;
						cur = next[cur].get(p[i]);
					}
//					System.out.println(l + " " + cur);
					if (l == p.length) {
						hs.add(cur);
//						System.out.println(p.length + " " + len[link[cur]] + " aa");
						l--;
						if (l <= len[link[cur]]) {

							cur = link[cur];
						}
					}
//					System.out.println(l + " " + cur);
				}
			}
//			System.out.println(Arrays.toString(len));
//			System.out.println(hs);
//			System.out.println(Arrays.toString(next));
			int ans = 0;
			for (int x : hs) {
				ans += cnt[x];
			}
			return ans;
		}

		SuffixAutomaton(char[] s) {
			int n = s.length;
			link = new int[n << 1];
			len = new int[n << 1];
			next = new TreeMap[n << 1];
			next[0] = new TreeMap<>();
			cnt = new int[n << 1];
			for (char c : s)
				addLetter(c);
			Integer[] order = new Integer[idx + 1];
			for (int i = 0; i < order.length; i++) {
				order[i] = i;
			}
			Arrays.sort(order, (u, v) -> (len[v] - len[u]));
			for (int i = 0; i < order.length; i++) {
				cnt[link[order[i]]] += cnt[order[i]];
			}

		}

		void addLetter(char c) {
			int cur = ++idx, p = lst;
			while (!next[p].containsKey(c)) {
				next[p].put(c, cur);
				p = link[p];
			}

			int q = next[p].get(c);
			if (q != cur)
				if (len[q] == len[p] + 1)
					link[cur] = q;
				else {
					int clone = ++idx;
					len[clone] = len[p] + 1;
					link[clone] = link[q];
					next[clone] = new TreeMap<>(next[q]);
					link[cur] = link[q] = clone;
					while (next[p].get(c) == q) {
						next[p].put(c, clone);
						p = link[p];
					}
				}
			cnt[cur] = 1;
			len[cur] = len[lst] + 1;
			next[cur] = new TreeMap<>();
			lst = cur;
		}
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader f) {
			br = new BufferedReader(f);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = Integer.parseInt(next());
			}
			return arr;
		}

	}

}