#include <bits/stdc++.h>
using namespace std;
const int W = 12;
int w;
int bitWiseAddRes[1 << W][1 << W];
char gate[W + 5];
int cnt[1 << W];
int extend[1 << (W << 1)];
int bitWiseAdd(int a, int b) {
  int res = 0;
  for (int i = 0; i < w; i++) {
    int l = (a & 1) | (b & 1);
    int h = (a & 1) & (b & 1);
    res |= l * (1 << (i << 1));
    res |= h * (1 << ((i << 1) | 1));
    a >>= 1;
    b >>= 1;
  }
  return res;
}
void precompute() {
  for (int i = 0; i < 1 << w; i++) {
    for (int j = 0; j < 1 << w; j++) {
      bitWiseAddRes[i][j] = bitWiseAdd(i, j);
    }
  }
}
int ans;
void gateToPoss(int idx, int sofar) {
  if (idx == w) {
    ans += extend[sofar];
    return;
  }
  switch (gate[idx]) {
    case 'A':
      gateToPoss(idx + 1, sofar << 2 | 0);
      gateToPoss(idx + 1, sofar << 2 | 1);
      break;
    case 'O':
      gateToPoss(idx + 1, sofar << 2 | 0);
      break;
    case 'X':
      gateToPoss(idx + 1, sofar << 2 | 0);
      gateToPoss(idx + 1, sofar << 2 | 3);
      break;
    case 'a':
      gateToPoss(idx + 1, sofar << 2 | 3);
      break;
    case 'o':
      gateToPoss(idx + 1, sofar << 2 | 1);
      gateToPoss(idx + 1, sofar << 2 | 3);
      break;
    case 'x':
      gateToPoss(idx + 1, sofar << 2 | 1);
      break;
  }
}
int main() {
  int n, m;
  scanf("%d %d %d", &w, &n, &m);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    cnt[a]++;
  }
  precompute();
  for (int i = 0; i < 1 << w; i++) {
    for (int j = 0; j < 1 << w; j++) {
      extend[bitWiseAddRes[i][j]] += cnt[i] * cnt[j];
    }
  }
  for (int i = 0; i < m; i++) {
    ans = 0;
    scanf("%s", gate);
    gateToPoss(0, 0);
    printf("%d\n", ans);
  }
  return 0;
}
