#include <bits/stdc++.h>
using namespace std;
int W;
int cnt[1 << 12];
int ter[1 << 12];
int nump[531441];
int M;
unordered_map<char, vector<int> > zerocombos;
int recurse(string &gate, int curTval, int pos) {
  if (pos == W) return nump[curTval];
  int ret = 0;
  for (auto x : zerocombos[gate[pos]])
    ret += recurse(gate, curTval * 3 + x, pos + 1);
  return ret;
}
int main() {
  int N;
  cin >> W >> N >> M;
  memset(cnt, 0, sizeof cnt);
  for (int i = 0; i < (int)(N); i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  int pow3[12];
  pow3[0] = 1;
  for (int i = 1; i <= (int)11; i++) pow3[i] = pow3[i - 1] * 3;
  for (int bin = 0; bin < (int)(1 << W); bin++) {
    int ternval = 0;
    for (int i = 0; i < (int)(W); i++) {
      if ((bin & (1 << i)) != 0) ternval += pow3[i];
    }
    ter[bin] = ternval;
  }
  memset(nump, 0, sizeof nump);
  for (int i = 0; i < (int)(1 << W); i++)
    for (int j = 0; j < (int)(1 << W); j++)
      nump[ter[i] + ter[j]] += cnt[i] * cnt[j];
  zerocombos['A'] = {0, 1};
  zerocombos['O'] = {0};
  zerocombos['X'] = {0, 2};
  zerocombos['a'] = {2};
  zerocombos['o'] = {1, 2};
  zerocombos['x'] = {1};
  for (int i = 0; i < (int)(M); i++) {
    string gate;
    cin >> gate;
    cout << recurse(gate, 0, 0) << "\n";
  }
  return 0;
}
