#include <bits/stdc++.h>
using namespace std;
int w, n, m;
int tot[1 << 12];
int tt[1 << 20];
int pw[30];
char s[20];
int twotothree(int x) {
  int re = 0;
  for (int i = 0; i < w; ++i) re += pw[i] * (x & 1), x >>= 1;
  return re;
}
int dfs(int o, int zong) {
  if (o > w) return tt[zong];
  if (s[o] == 'A')
    return dfs(o + 1, zong + 0 * pw[w - o]) + dfs(o + 1, zong + 1 * pw[w - o]);
  if (s[o] == 'O') return dfs(o + 1, zong + 0 * pw[w - o]);
  if (s[o] == 'X')
    return dfs(o + 1, zong + 0 * pw[w - o]) + dfs(o + 1, zong + 2 * pw[w - o]);
  if (s[o] == 'a') return dfs(o + 1, zong + 2 * pw[w - o]);
  if (s[o] == 'o')
    return dfs(o + 1, zong + 1 * pw[w - o]) + dfs(o + 1, zong + 2 * pw[w - o]);
  if (s[o] == 'x') return dfs(o + 1, zong + 1 * pw[w - o]);
}
int main() {
  scanf("%d%d%d", &w, &n, &m);
  pw[0] = 1;
  for (int i = 1; i <= w; ++i) pw[i] = pw[i - 1] * 3;
  for (int i = 1; i <= n; ++i) {
    int a;
    scanf("%d", &a);
    ++tot[a];
  }
  for (int i = 0; i < (1 << w); ++i)
    for (int j = 0; j < (1 << w); ++j) {
      tt[twotothree(i) + twotothree(j)] += tot[i] * tot[j];
    }
  for (int i = 1; i <= m; ++i) {
    scanf("%s", s + 1);
    printf("%d\n", dfs(1, 0));
  }
}
