#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  long long ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
inline long long add(long long x, long long y) {
  return x + y >= 998244353 ? x + y - 998244353 : x + y;
}
inline long long sub(long long x, long long y) {
  return x - y < 0 ? x - y + 998244353 : x - y;
}
inline long long mul(long long x, long long y) {
  return 1LL * x * y % 998244353;
}
long long pw[15], cnt[1 << 24];
long long a[50005];
long long w, n, Q;
char s[15];
long long get(long long x) {
  long long res = 0;
  for (long long i = 0; i < w; i++)
    if (x & (1 << i)) res += pw[i];
  return res;
}
long long dfs(long long dep, long long cur) {
  if (dep == w) return cnt[cur];
  if (s[dep] == 'A') return dfs(dep + 1, cur) + dfs(dep + 1, cur + pw[dep]);
  if (s[dep] == 'O') return dfs(dep + 1, cur);
  if (s[dep] == 'X') return dfs(dep + 1, cur) + dfs(dep + 1, cur + pw[dep] * 2);
  if (s[dep] == 'a') return dfs(dep + 1, cur + pw[dep] * 2);
  if (s[dep] == 'o')
    return dfs(dep + 1, cur + pw[dep]) + dfs(dep + 1, cur + pw[dep] * 2);
  if (s[dep] == 'x') return dfs(dep + 1, cur + pw[dep]);
}
signed main() {
  cin >> w >> n >> Q;
  pw[0] = 1;
  for (long long i = 1; i <= w; i++) pw[i] = pw[i - 1] * 3;
  for (long long i = 1; i <= n; i++) a[read()]++;
  for (long long i = 0; i < (1 << w); i++) {
    for (long long j = 0; j < (1 << w); j++) {
      cnt[get(i) + get(j)] += a[i] * a[j];
    }
  }
  while (Q--) {
    scanf("%s", s);
    reverse(s, s + w);
    printf("%lld\n", dfs(0, 0));
  }
  return 0;
}
