#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int w, n, m;
  cin >> w >> n >> m;
  vector<int> pw3(w + 1), cnt2((1 << w), 0);
  pw3[0] = 1;
  for (int i = 1; i <= w; ++i) pw3[i] = pw3[i - 1] * 3;
  vector<int> cnt3(pw3[w], 0);
  for (int x, i = 0; i < n; ++i) {
    cin >> x;
    ++cnt2[x];
    int y = 0;
    for (int j = 0; j < w; ++j)
      if ((x >> j) & 1) y += pw3[j];
    ++cnt3[y];
  }
  for (int i = 0; i < w; ++i)
    for (int x = 0; x < pw3[w]; ++x) {
      int t = x / pw3[i] % 3;
      if (!t) cnt3[x + pw3[i] * 2] += cnt3[x];
      if (t == 1) cnt3[x + pw3[i]] += cnt3[x];
    }
  vector<vector<int> > f = {{2, 0}, {0, -1}, {0, 1}, {-1, 1}, {1, 2}, {1, 0}};
  map<char, int> M;
  M['A'] = 0;
  M['O'] = 1;
  M['X'] = 2;
  M['a'] = 3;
  M['o'] = 4;
  M['x'] = 5;
  while (m--) {
    string s;
    cin >> s;
    int ans = 0;
    function<void(int, int, int)> solve = [&](int i, int x, int y) {
      if (i == w) {
        ans += cnt3[x] * cnt2[y];
        return;
      }
      auto &t = f[M[s[w - i - 1]]];
      for (int z = 0; z < 2; ++z)
        if (~t[z]) solve(i + 1, x + t[z] * pw3[i], y | (z << i));
      return;
    };
    solve(0, 0, 0);
    cout << ans << endl;
  }
  return 0;
}
