Problem: Alice has a computer that operates on w-bit integers. The computer has n registers for values. The current content of the registers is given as an array a_1, a_2, …, a_n. 

The computer uses so-called "number gates" to manipulate this data. Each "number gate" takes two registers as inputs and calculates a function of the two values stored in those registers. Note that you can use the same register as both inputs.

Each "number gate" is assembled from bit gates. There are six types of bit gates: AND, OR, XOR, NOT AND, NOT OR, and NOT XOR, denoted "A", "O", "X", "a", "o", "x", respectively. Each bit gate takes two bits as input. Its output given the input bits b_1, b_2 is given below:

\begin{matrix} b_1 & b_2 & A & O & X & a & o & x \\\ 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 \\\ 0 & 1 & 0 & 1 & 1 & 1 & 0 & 0 \\\ 1 & 0 & 0 & 1 & 1 & 1 & 0 & 0 \\\ 1 & 1 & 1 & 1 & 0 & 0 & 0 & 1 \\\ \end{matrix} 

To build a "number gate", one takes w bit gates and assembles them into an array. A "number gate" takes two w-bit integers x_1 and x_2 as input. The "number gate" splits the integers into w bits and feeds the i-th bit of each input to the i-th bit gate. After that, it assembles the resulting bits again to form an output word. 

For instance, for 4-bit computer we might have a "number gate" "AXoA" (AND, XOR, NOT OR, AND). For two inputs, 13 = 1101_2 and 10 = 1010_2, this returns 12 = 1100_2, as 1 and 1 is 1, 1 xor 0 is 1, not (0 or 1) is 0, and finally 1 and 0 is 0. 

You are given a description of m "number gates". For each gate, your goal is to report the number of register pairs for which the "number gate" outputs the number 0. In other words, find the number of ordered pairs (i,j) where 1 ≤ i,j ≤ n, such that w_k(a_i, a_j) = 0, where w_k is the function computed by the k-th "number gate".

Input

The first line contains three integers: w, n, and m~(1 ≤ w ≤ 12, 1 ≤ n ≤ 3⋅ 10^4, 1 ≤ m ≤ 5⋅ 10^4) — the word size, the number of variables, and the number of gates.

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < 2^w) — the value of variables stored in the registers.

Each of the next m lines contains a string g_j~(|g_j| = w) with a description of a single gate. Each character of g_j is one of "A", "O", "X", "a", "o", "x".

Output

Print m lines. The i-th line should contain the number of ordered pairs of variables for which the i-th gate returns zero.

Examples

Input

4 3 1
13 10 6
AXoA


Output

3


Input

1 7 6
0 1 1 0 1 0 0
A
O
X
a
o
x


Output

40
16
25
9
33
24


Input

6 2 4
47 12
AOXaox
AAaaAA
xxxxxx
XXXXXX


Output

2
3
0
2


Input

2 2 2
2 0
xO
Ox


Output

2
0

Note

In the first test case, the inputs in binary are 1101, 1010, 0110. The pairs that return 0 are (13, 6), (6, 13), and (6, 6). As it was already mentioned in the problem statement, 13 ⊕ 10 = 10 ⊕ 13 = 12. The other pairs are 13 ⊕ 13 = 11, 10 ⊕ 10 = 8 and 10 ⊕ 6 = 6 ⊕ 10 = 4. 

Solution (in JAVA):

Solution:
//package lyft2018;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class F {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int w = ni(), n = ni(), m = ni();
		int[] a = na(n);
		int[] f = new int[1<<w];
		for(int v : a)f[v]++;
		
		// and,or,xor
		// 00 11 01or10
		// 2^12
		
		int[] p3 = new int[w+1];
		p3[0] = 1;
		for(int i = 0;i < w;i++){
			p3[i+1] = p3[i] * 3;
		}
		int[] gf = new int[p3[w]];
		
		int[] plus3 = new int[1<<w];
		for(int i = 0;i < 1<<w;i++){
			int h = 0;
			for(int j = w-1;j >= 0;j--){
				h = h * 3 + (i>>>j&1);
			}
			gf[h] += f[i];
			plus3[i] = h;
		}
		
		for(int k = 0;k < w;k++){
			int[] b = new int[w];
			int p = 0;
			do{
				if(b[w-1-k] < 2){
					gf[p+p3[k] * (2-b[w-1-k])] += gf[p];
				}
				p++;
			}while(inc(b, 3));
		}
		
		for(int z = 0;z < m;z++){
			char[] s = ns(w);
			int amask = 0, omask = 0, xmask = 0;
			int tar = 0;
			for(int i = w-1;i >= 0;i--){
				if(s[i] >= 'a' && s[i] <= 'z'){
					tar |= 1<<w-i-1;
				}
				if(s[i] == 'A' || s[i] == 'a')amask |= 1<<w-1-i;
				if(s[i] == 'O' || s[i] == 'o')omask |= 1<<w-1-i;
				if(s[i] == 'X' || s[i] == 'x')xmask |= 1<<w-1-i;
			}
			int must0 = 0;
			int must1 = 0;
			for(int i = 0;i < w;i++){
				if(amask<<~i<0 && tar<<~i<0)must1 |= 1<<i;
				if(omask<<~i<0 && tar<<~i>=0)must0 |= 1<<i;
			}
			int must = must0|must1;
			
			// a
			// L res R
			// 0 0 2
			// 1 0 0
			// 1 1 1
			
			// o
			// L res R
			// 0 0 0
			// 0 1 1
			// 1 1 2
			
			long ans = 0;
			for(int i = 0;i < 1<<w;i++){
				if((i&must) != must1)continue;
				int x = plus3[(i^tar)&xmask];
				int o = plus3[i&omask] + plus3[tar&omask];
				int A = plus3[i&amask&tar] // L = 1
						+ plus3[amask^i&amask]*2;
				ans += f[i] * gf[A+o+x];
			}
//			for(int i = 0;i < 1<<w;i++){
//				int t = i&~xmask;
//				if(t == tar){
//					ans -=f[i] * f[i];
//					
//				}
//			}
			out.println(ans);
		}
	}
	
	public static boolean inc(int[] a, int base) {
		int n = a.length;
		int i;
		for (i = n - 1; i >= 0 && a[i] == base - 1; i--)
			;
		if (i == -1)
			return false;

		a[i]++;
		Arrays.fill(a, i + 1, n, 0);
		return true;
	}

	
	public static int[] zetaTransform(int[] f)
	{
		int H = Integer.numberOfTrailingZeros(f.length);
		for(int i = 0;i < H;i++){
			for(int j = 0;j < 1<<H;j++){
				if(j<<~i>=0){
					f[j] += f[j|1<<i];
				}
			}
		}
		return f;
	}

	
	void run() throws Exception
	{
//		int n = 30000, m = 50000;
//		Random gen = new Random();
//		StringBuilder sb = new StringBuilder();
//		sb.append(12 + " ");
//		sb.append(n + " ");
//		sb.append(m + "\n");
//		for (int i = 0; i < n; i++) {
//			sb.append(gen.nextInt(1<<12) + " ");
//		}
//		sb.append("\n");
//		for (int i = 0; i < m; i++) {
//			char[] x = "AOXaox".toCharArray();
//			for(int j = 0;j < 12;j++){
//				sb.append(x[gen.nextInt(6)]);
//			}
//			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 F().run(); }
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}