#include <bits/stdc++.h>
using namespace std;
const int N = 6e5;
int w, n, m;
int cnt[N], tas[N], sum[N], pw3[N];
char st[N];
int dfs(int t = 0, int v = 0) {
  if (t == w) {
    return sum[v];
  }
  int q = pw3[t];
  switch (st[w - t - 1]) {
    case 'A':
      return dfs(t + 1, v) + dfs(t + 1, v + q);
    case 'O':
      return dfs(t + 1, v);
    case 'X':
      return dfs(t + 1, v) + dfs(t + 1, v + q * 2);
    case 'a':
      return dfs(t + 1, v + q * 2);
    case 'o':
      return dfs(t + 1, v + q) + dfs(t + 1, v + q * 2);
    case 'x':
      return dfs(t + 1, v + q);
  }
  return 0;
}
int main() {
  scanf("%d%d%d", &w, &n, &m);
  for (int i = 1; i <= n; ++i) {
    int a = 0;
    scanf("%d", &a), cnt[a]++;
  }
  pw3[0] = 1;
  for (int i = 1; i < w; ++i) pw3[i] = pw3[i - 1] * 3;
  for (int i = 0; i < (1 << w); ++i) {
    int p = 0;
    for (int j = 0; j < w; ++j)
      if (i & (1 << j)) p += pw3[j];
    tas[i] = p;
  }
  for (int i = 0; i < (1 << w); ++i)
    for (int j = 0; j < (1 << w); ++j) sum[tas[i] + tas[j]] += cnt[i] * cnt[j];
  for (int i = 1; i <= m; ++i) {
    scanf("%s", st);
    printf("%d\n", dfs());
  }
}
