#include <bits/stdc++.h>
using namespace std;
const int N = 12;
int w, n, Q, cnt[1 << N | 1], val[1 << N | 1][1 << N | 1], x;
char s[N + 1];
int main() {
  scanf("%d%d%d", &w, &n, &Q);
  while (n--) {
    scanf("%d", &x);
    cnt[x]++;
  }
  for (int i = 0; i < 1 << w; i++)
    for (int j = 0; j < 1 << w; j++) {
      int s = 0;
      for (int k = 0; k < w; k++)
        if (((1 << k) & i) && ((1 << k) & j)) s += 1 << k;
      val[j][s] += cnt[i];
    }
  while (Q--) {
    scanf("%s", s);
    int ans = 0;
    reverse(s, s + w);
    int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0;
    for (int i = 0; i < w; i++)
      if (s[i] == 'a')
        sum1 |= 1 << i;
      else if (s[i] == 'O')
        sum2 |= 1 << i;
      else if (s[i] == 'A')
        sum3 |= 1 << i;
      else if (s[i] == 'X')
        sum4 |= 1 << i;
      else if (s[i] == 'x')
        sum5 |= 1 << i;
      else
        sum6 |= 1 << i;
    for (int i = 0; i < 1 << w; i++)
      if (cnt[i] && (sum1 & i) == sum1 && (sum2 & i) == 0) {
        int s1 = sum1, s2 = (1 << w) - 1;
        s2 -= sum3 & (((1 << w) - 1) ^ i);
        s1 += sum4 & i;
        s1 += sum5 & (((1 << w) - 1) ^ i);
        s1 += sum6 & (((1 << w) - 1) ^ i);
        s2 -= sum6 & i;
        ans += cnt[i] * val[s2][s1];
      }
    printf("%d\n", ans);
  }
}
