#include <bits/stdc++.h>
int w, n, m, c[1 << 12], id[1 << 12], f[531441];
int dfs(char* g, int s, int t) {
  if (!*g) return c[s] * f[t];
  s <<= 1;
  t *= 3;
  switch (*g++) {
    case 'A':
      return dfs(g, s, t + 2) + dfs(g, s | 1, t);
    case 'O':
      return dfs(g, s, t);
    case 'X':
      return dfs(g, s, t) + dfs(g, s | 1, t + 1);
    case 'a':
      return dfs(g, s | 1, t + 1);
    case 'o':
      return dfs(g, s, t + 1) + dfs(g, s | 1, t + 2);
    case 'x':
      return dfs(g, s, t + 1) + dfs(g, s | 1, t);
  }
}
int main() {
  scanf("%d%d%d", &w, &n, &m);
  for (int i = 1; i < 1 << w; i++) id[i] = id[i / 2] * 3 + i % 2;
  while (n--) {
    int a;
    scanf("%d", &a);
    c[a]++;
    f[id[a]]++;
  }
  for (int i = 0, lim = 1; i < w; i++, lim *= 3)
    for (int s = 0; s < 1 << w; s += 1 << i + 1)
      for (int t = 0, j = id[s]; t < lim; t++, j++)
        f[j + lim * 2] += f[j] + f[j + lim];
  while (m--) {
    char g[15];
    scanf("%s", g);
    printf("%d\n", dfs(g, 0, 0));
  }
}
