#include <bits/stdc++.h>
using namespace std;
int occur3[1000000];
int occur[(1 << 12)];
int three[(1 << 12)];
int w, n, m;
int var[30000];
int add[256][2];
bool inval[256][2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  scanf("%d%d%d", &w, &n, &m);
  clock_t z = clock();
  for (int i = 0; i < n; i++) {
    scanf("%d", &var[i]);
    occur[var[i]]++;
  }
  for (int i = 0; i < (1 << w); i++) {
    int ix = 0;
    for (int j = 0; j < w; j++) {
      ix = ix * 3 + ((i & (1 << j)) > 0);
    }
    three[i] = ix;
  }
  cerr << (double)(clock() - z) / CLOCKS_PER_SEC << endl;
  for (int i = 0; i < (1 << w); i++) {
    for (int j = 0; j < (1 << w); j++) {
      occur3[three[i] + three[j]] += occur[i] * occur[j];
    }
  }
  cerr << (double)(clock() - z) / CLOCKS_PER_SEC << endl;
  add['x'][0] = add['o'][0] = add['A'][1] = 1;
  add['a'][0] = add['o'][1] = add['X'][1] = 2;
  add['O'][0] = add['A'][0] = add['X'][0] = 0;
  inval['x'][1] = inval['a'][1] = inval['O'][1] = true;
  for (int i = 0; i < m; i++) {
    char gate[15];
    scanf("%s", &gate);
    long long ans = 0;
    for (int j = 0; j < (1 << w); j++) {
      int query = 0;
      bool valid = true;
      for (int k = w - 1; k >= 0; k--) {
        int toadd = add[gate[k]][(j & (1 << k)) > 0];
        if (inval[gate[k]][(j & (1 << k)) > 0]) valid = false;
        query = query * 3 + toadd;
      }
      if (valid) ans += occur3[query];
    }
    cout << ans << "\n";
  }
  cerr << (double)(clock() - z) / CLOCKS_PER_SEC << endl;
}
