#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
int w, n, m;
int a[4444];
int mk[1 << 20];
char s[15];
inline int getnewmask(int mask, int bit, char c) {
  if (bit == 0) {
    if (c == 'A') return mask * 3 + 2;
    if (c == 'O') return mask * 3 + 0;
    if (c == 'X') return mask * 3 + 0;
    if (c == 'a') return -1;
    if (c == 'o') return mask * 3 + 1;
    if (c == 'x') return mask * 3 + 1;
  } else {
    if (c == 'A') return mask * 3 + 0;
    if (c == 'O') return -1;
    if (c == 'X') return mask * 3 + 1;
    if (c == 'a') return mask * 3 + 1;
    if (c == 'o') return mask * 3 + 2;
    if (c == 'x') return mask * 3 + 0;
  }
}
int res;
void go(int currnumber, int currmask, int pos) {
  if (currmask < 0) return;
  if (pos == w) {
    res += a[currnumber] * mk[currmask];
    return;
  }
  char c = s[pos];
  go(currnumber * 2, getnewmask(currmask, 0, c), pos + 1);
  go(currnumber * 2 + 1, getnewmask(currmask, 1, c), pos + 1);
}
int solve() {
  res = 0;
  go(0, 0, 0);
  return res;
}
int main() {
  cin >> w >> n >> m;
  for (int i = (0); i < (n); i++) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  for (int i = (0); i < (1 << w); i++) {
    for (int j = (0); j < (1 << w); j++) {
      int t = 0;
      for (int k = w - 1; k >= 0; k--) {
        t *= 3;
        if (j & (1 << k))
          t += 2;
        else if (i & (1 << k))
          t++;
        else
          t += 0;
      }
      mk[t] += a[i];
    }
  }
  for (int i = (0); i < (m); i++) {
    scanf(" %s", s);
    printf("%d\n", solve());
  }
  return 0;
}
