#include <bits/stdc++.h>
using namespace std;
int i, j, k, m, n, l, w;
int ans;
const int N = 1 << 12;
int cnt[N], p3[N], f3[N], comb[1000000];
string s;
vector<int> good[256];
void go(int at, int m3) {
  if (at == ((int)s.size()))
    ans += comb[m3];
  else {
    for (int x : good[s[w - at - 1]]) {
      go(at + 1, m3 + x * p3[at]);
    }
  }
}
int main() {
  good['A'] = {0, 1};
  good['O'] = {0};
  good['X'] = {0, 2};
  good['a'] = {2};
  good['o'] = {1, 2};
  good['x'] = {1};
  while (cin >> w >> n >> m) {
    memset(cnt, 0, sizeof(cnt));
    ;
    memset(comb, 0, sizeof(comb));
    ;
    for (int i = 0; i < n; i++) {
      cin >> j;
      cnt[j]++;
    }
    p3[0] = 1;
    for (int i = 1; i <= w; i++) p3[i] = p3[i - 1] * 3;
    for (int i = 0; i < (1 << w); i++) {
      f3[i] = 0;
      for (int j = 0; j < w; j++)
        if ((1 << j) & i) f3[i] += p3[j];
    }
    for (int i = 0; i < (1 << w); i++)
      for (int j = 0; j < (1 << w); j++) {
        comb[f3[i & j] + f3[i | j]] += cnt[i] * cnt[j];
      }
    while (m--) {
      cin >> s;
      ans = 0;
      go(0, 0);
      cout << ans << endl;
    }
  }
  return 0;
}
