#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long power(long long x, int y) {
  long long t = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) t = t * x;
  return t;
}
int w, n, m, tot;
int a[1000005], b[1000005];
long long ans;
string s;
void dfs(int len, int now, int num) {
  if (len == w) {
    b[now] += a[num];
    return;
  } else {
    dfs(len + 1, now * 3 + 2, num);
    dfs(len + 1, now * 3 + ((num >> (w - len - 1)) & 1), num);
  }
}
void getans(int len, int now, int num) {
  if (len == w) {
    ans += b[now] * a[num];
    return;
  } else {
    if (s[len] == 'A') {
      getans(len + 1, now * 3, (num << 1) + 1);
      getans(len + 1, now * 3 + 2, num << 1);
    } else if (s[len] == 'O') {
      getans(len + 1, now * 3, num << 1);
    } else if (s[len] == 'X') {
      getans(len + 1, now * 3, num << 1);
      getans(len + 1, now * 3 + 1, (num << 1) + 1);
    } else if (s[len] == 'a') {
      getans(len + 1, now * 3 + 1, (num << 1) + 1);
    } else if (s[len] == 'o') {
      getans(len + 1, now * 3 + 2, (num << 1) + 1);
      getans(len + 1, now * 3 + 1, num << 1);
    } else if (s[len] == 'x') {
      getans(len + 1, now * 3, (num << 1) + 1);
      getans(len + 1, now * 3 + 1, num << 1);
    }
  }
}
int main() {
  w = read();
  n = read();
  m = read();
  tot = 1 << w;
  for (int i = 1; i <= (n); i++) {
    int x = read();
    a[x]++;
  }
  for (int i = 0; i < (tot); i++) dfs(0, 0, i);
  for (int i = 1; i <= (m); i++) {
    getline(cin, s);
    getans(0, 0, 0);
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}
