#include <bits/stdc++.h>
using namespace std;
const long long N2 = (1 << 12) + 10, N3 = 1e6 + 10, MOD = 998244353;
long long w, n, m;
long long ile2[N2];
long long ile3[N3];
long long pot3 = 1;
vector<pair<long long, long long> > op[200];
string s;
long long res;
void szukaj(long long i, long long a, long long b) {
  if (i == w) {
    res += ile3[a] * ile3[b];
    return;
  }
  szukaj(i + 1, 3 * a + op[s[i]][0].first, 3 * b + op[s[i]][0].second);
  if ((long long)((op[s[i]]).size()) == 1) return;
  szukaj(i + 1, 3 * a + op[s[i]][1].first, 3 * b + op[s[i]][1].second);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cout << setprecision(9) << fixed;
  cerr << setprecision(6) << fixed;
  op['A'].push_back(pair<long long, long long>(0, 2));
  op['A'].push_back(pair<long long, long long>(1, 0));
  op['O'].push_back(pair<long long, long long>(0, 0));
  op['X'].push_back(pair<long long, long long>(0, 0));
  op['X'].push_back(pair<long long, long long>(1, 1));
  op['a'].push_back(pair<long long, long long>(1, 1));
  op['o'].push_back(pair<long long, long long>(0, 1));
  op['o'].push_back(pair<long long, long long>(1, 2));
  op['x'].push_back(pair<long long, long long>(0, 1));
  op['x'].push_back(pair<long long, long long>(1, 0));
  cin >> w >> n >> m;
  for (long long i = ((0)); i <= ((n)-1); i++) {
    long long a;
    cin >> a;
    ile2[a]++;
  }
  for (long long i = ((0)); i <= ((w)-1); i++) pot3 *= 3;
  for (long long i = ((0)); i <= ((pot3)-1); i++) {
    vector<long long> tab(w, 0);
    long long pom = i;
    for (long long j = (w - 1); j >= (0); j--) {
      tab[j] = pom % 3;
      pom /= 3;
    }
    bool jest2 = false;
    long long gdzie = 0;
    for (long long j = 0; j < w; j++)
      if (tab[j] == 2) {
        jest2 = true;
        gdzie = j;
        break;
      }
    if (!jest2) {
      bitset<12> bits;
      reverse((tab).begin(), (tab).end());
      for (long long i = ((0)); i <= ((w)-1); i++) bits[i] = tab[i];
      ile3[i] = ile2[bits.to_ulong()];
      continue;
    }
    tab[gdzie] = 0;
    pom = 0;
    for (long long j = ((0)); j <= ((w)-1); j++) {
      pom *= 3;
      pom += tab[j];
    }
    ile3[i] += ile3[pom];
    tab[gdzie] = 1;
    pom = 0;
    for (long long j = ((0)); j <= ((w)-1); j++) {
      pom *= 3;
      pom += tab[j];
    }
    ile3[i] += ile3[pom];
  }
  for (long long i = ((0)); i <= ((m)-1); i++) {
    cin >> s;
    res = 0;
    szukaj(0, 0, 0);
    cout << res << "\n";
  }
}
