#include <bits/stdc++.h>
using namespace std;
void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
template <typename... Args>
void dbg(Args... args) {
  ((cout << args << " "), ...);
  cout << "\n";
}
int w, n, m;
int a[30010];
int cnt[1 << 13];
int wt[1 << 13];
int num[2000000];
int p3[20];
long long dfs(int cur, string s, int pv) {
  long long ret = 0;
  if (pv < 0) return num[cur];
  if (s[pv] == 'A') {
    ret += dfs(cur, s, pv - 1);
    ret += dfs(cur + p3[pv], s, pv - 1);
  } else if (s[pv] == 'O') {
    ret += dfs(cur, s, pv - 1);
  } else if (s[pv] == 'X') {
    ret += dfs(cur, s, pv - 1);
    ret += dfs(cur + 2 * p3[pv], s, pv - 1);
  } else if (s[pv] == 'a') {
    ret += dfs(cur + 2 * p3[pv], s, pv - 1);
  } else if (s[pv] == 'o') {
    ret += dfs(cur + p3[pv], s, pv - 1);
    ret += dfs(cur + 2 * p3[pv], s, pv - 1);
  } else if (s[pv] == 'x') {
    ret += dfs(cur + p3[pv], s, pv - 1);
  }
  return ret;
}
void solve() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  cout << dfs(0, s, w - 1) << "\n";
}
int main() {
  use_cio();
  cin >> w >> n >> m;
  for (int i = 0; i < (n); i++) cin >> a[i], cnt[a[i]]++;
  p3[0] = 1;
  for (int i = 0; i < (w); i++) p3[i + 1] = p3[i] * 3;
  for (int i = 0; i < (1 << w); i++) {
    for (int j = 0; j < (w); j++) {
      if (i & (1 << j)) wt[i] += p3[j];
    }
  }
  for (int i = 0; i < (1 << w); i++) {
    for (int j = 0; j < (1 << w); j++) {
      num[wt[i] + wt[j]] += cnt[i] * cnt[j];
    }
  }
  for (int i = 0; i < (m); i++) solve();
}
