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:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            FBooleanComputer solver = new FBooleanComputer();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class FBooleanComputer {
        int[][] accepted = new int[128][0];
        int w;
        int[] pairs;
        DigitBase base3 = new DigitBase(3);

        {
            accepted['A'] = SequenceUtils.wrapArray(0, 1);
            accepted['O'] = SequenceUtils.wrapArray(0);
            accepted['X'] = SequenceUtils.wrapArray(0, 2);
            accepted['a'] = SequenceUtils.wrapArray(2);
            accepted['o'] = SequenceUtils.wrapArray(1, 2);
            accepted['x'] = SequenceUtils.wrapArray(1);
        }

        public void solve(int testNumber, FastInput in, FastOutput out) {
            w = in.readInt();
            int n = in.readInt();
            int m = in.readInt();

            int[] cnts = new int[1 << w];
            for (int i = 0; i < n; i++) {
                cnts[in.readInt()]++;
            }


            pairs = new int[(int) base3.valueOfBit(w)];
            for (int i = 0; i < cnts.length; i++) {
                for (int j = 0; j < cnts.length; j++) {
                    int val = 0;
                    for (int k = 0; k < w; k++) {
                        val += (int) base3.valueOfBit(k) * (Bits.bitAt(i, k) + Bits.bitAt(j, k));
                    }
                    pairs[val] += cnts[i] * cnts[j];
                }
            }


            char[] cmd = new char[w];
            for (int i = 0; i < m; i++) {
                in.readString(cmd, 0);
                SequenceUtils.reverse(cmd, 0, w - 1);
                int ans = dfs(cmd, 0, 0);
                out.println(ans);
            }
        }

        public int dfs(char[] cmd, int scan, int val) {
            if (scan == cmd.length) {
                return pairs[val];
            }
            int sum = 0;
            for (int x : accepted[cmd[scan]]) {
                sum += dfs(cmd, scan + 1, val + (int) base3.valueOfBit(scan) * x);
            }
            return sum;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static boolean isMultiplicationOverflow(long a, long b, long limit) {
            if (limit < 0) {
                limit = -limit;
            }
            if (a < 0) {
                a = -a;
            }
            if (b < 0) {
                b = -b;
            }
            if (a == 0 || b == 0) {
                return false;
            }
            //a * b > limit => a > limit / b
            return a > limit / b;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public int readString(char[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (char) next;
                next = read();
            }

            return offset - originalOffset;
        }

    }

    static class SequenceUtils {
        public static int[] wrapArray(int... x) {
            return x;
        }

        public static void swap(char[] data, int i, int j) {
            char tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

        public static void reverse(char[] data, int l, int r) {
            while (l < r) {
                swap(data, l, r);
                l++;
                r--;
            }
        }

        public static boolean equal(long[] a, int al, int ar, long[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

    static class LongList implements Cloneable {
        private int size;
        private int cap;
        private long[] data;
        private static final long[] EMPTY = new long[0];

        public LongList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new long[cap];
            }
        }

        public LongList(LongList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public LongList() {
            this(0);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public void add(long x) {
            ensureSpace(size + 1);
            data[size++] = x;
        }

        public void addAll(long[] x, int offset, int len) {
            ensureSpace(size + len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public void addAll(LongList list) {
            addAll(list.data, 0, list.size);
        }

        public long tail() {
            checkRange(0);
            return data[size - 1];
        }

        public long[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof LongList)) {
                return false;
            }
            LongList other = (LongList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + Long.hashCode(data[i]);
            }
            return h;
        }

        public LongList clone() {
            LongList ans = new LongList();
            ans.addAll(this);
            return ans;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput println(int c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class DigitBase {
        private long[] pow;
        private long base;

        public DigitBase(long base) {
            if (base <= 1) {
                throw new IllegalArgumentException();
            }
            this.base = base;
            LongList ll = new LongList(64);
            ll.add(1);
            while (!DigitUtils.isMultiplicationOverflow(ll.tail(), base, Long.MAX_VALUE)) {
                ll.add(ll.tail() * base);
            }
            pow = ll.toArray();
        }

        public long valueOfBit(int i) {
            return pow[i];
        }

    }

    static class Bits {
        private Bits() {
        }

        public static int bitAt(int x, int i) {
            return (x >> i) & 1;
        }

    }
}