#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int N = 1e6 + 6;
int w, n, m, a[N];
long long cnt[N], cnt2[N];
int grupo[500][2];
string s;
long long go(int at, int val) {
  if (at < 0) return cnt2[val];
  char c = s[at];
  long long ret = 0;
  for (int i = 0; i < 2; i++) {
    if (grupo[c][i] == -1) continue;
    ret += go(at - 1, (val * 3) + grupo[c][i]);
  }
  return ret;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin >> w >> n >> m;
  grupo['A'][0] = 0;
  grupo['A'][1] = 1;
  grupo['O'][0] = 0;
  grupo['O'][1] = -1;
  grupo['X'][0] = 0;
  grupo['X'][1] = 2;
  grupo['a'][0] = 2;
  grupo['a'][1] = -1;
  grupo['o'][0] = 1;
  grupo['o'][1] = 2;
  grupo['x'][0] = 1;
  grupo['x'][1] = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int M = (1 << w);
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      int val = 0;
      for (int k = 0; k < w; k++) {
        int bi = (i >> k) & 1;
        int bj = (j >> k) & 1;
        val *= 3;
        val += bi + bj;
      }
      cnt2[val] += cnt[i] * cnt[j];
    }
  }
  while (m--) {
    cin >> s;
    long long ans = go(s.size() - 1, 0);
    cout << ans << endl;
  }
  return 0;
}
