#include <bits/stdc++.h>
using namespace std;
const int maxw = 13;
const int maxn = 30005;
const int maxs = 1600000;
int n, m, w;
int s1, s2;
long long ans;
int pw[maxw], F[maxs];
char buf[maxw];
int chkpos(bool d, char c) {
  switch (c) {
    case 'A':
      return (d == 0) ? 2 : 0;
    case 'O':
      return (d == 0) ? 0 : -1;
    case 'X':
      return (d == 0) ? 0 : 1;
    case 'a':
      return (d == 0) ? -1 : 1;
    case 'o':
      return (d == 0) ? 1 : 2;
    case 'x':
      return (d == 0) ? 1 : 0;
  }
  return -1;
}
void dfs(int depth) {
  if (depth == w) {
    ans += 1ll * F[s2] * F[s1];
    return;
  }
  int addS;
  addS = chkpos(0, buf[depth]);
  if (addS != -1) {
    s2 += addS * pw[depth];
    dfs(depth + 1);
    s2 -= addS * pw[depth];
  }
  addS = chkpos(1, buf[depth]);
  if (addS != -1) {
    s1 += pw[depth], s2 += addS * pw[depth];
    dfs(depth + 1);
    s1 -= pw[depth], s2 -= addS * pw[depth];
  }
}
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 ai, state, i = 1; i <= n; i++) {
    scanf("%d", &ai), state = 0;
    for (int j = 0; j < w; j++) state += pw[j] * ((ai >> j) & 1);
    ++F[state];
  }
  for (int i = 0; i < pw[w]; i++)
    for (int j = w - 1; j >= 0; j--)
      if ((i / pw[j]) % 3 == 2) {
        F[i] = F[i - pw[j]] + F[i - 2 * pw[j]];
        break;
      }
  for (int i = 1; i <= m; i++) {
    scanf("%s", buf), reverse(buf, buf + w);
    dfs(0), printf("%d\n", ans), ans = 0;
  }
  return 0;
}
