#include <bits/stdc++.h>
using namespace std;
int n, m, mll[5][5], md = 1e9 + 7;
vector<int> v[500];
char in[501];
inline void sb(int &x, int y) {
  if ((x -= y) < 0) x += 5;
}
inline void ml(vector<int> &a, vector<int> &b, int bg) {
  int d = 0;
  for (int i = 1; i < (int)(5); ++i)
    if (mll[a[bg]][i] == b[bg]) {
      d = i;
      break;
    }
  for (int i = bg; i < (int)(m); ++i) sb(b[i], mll[d][a[i]]);
}
int main() {
  for (int i = 0; i < (int)(5); ++i)
    for (int j = 0; j < (int)(5); ++j) mll[i][j] = i * j % 5;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); ++i) {
    scanf("%s", in);
    v[i].resize(m);
    for (int j = 0; j < (int)(m); ++j) v[i][j] = in[j] - 'a';
  }
  int w = 0;
  for (int i = 0; i < (int)(m); ++i) {
    int k = -1;
    for (int j = w; j < (int)(n); ++j)
      if (v[j][i]) {
        k = j;
        break;
      }
    if (k == -1) continue;
    swap(v[w], v[k]);
    ++w;
    for (int j = w; j < (int)(n); ++j)
      if (v[j][i]) ml(v[w - 1], v[j], i);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%s", in);
    vector<int> z(m);
    for (int i = 0; i < (int)(m); ++i) z[i] = in[i] - 'a';
    int an = 1, w = 0;
    for (int i = 0; i < (int)(n); ++i) {
      while (w < m && v[i][w] == 0) {
        if (z[w] != 0) {
          an = 0;
          break;
        }
        ++w;
      }
      if (an == 0) break;
      if (w == m)
        an = (long long)an * 5 % md;
      else {
        if (z[w] != 0) ml(v[i], z, w);
        ++w;
      }
    }
    while (w < m)
      if (z[w++] != 0) {
        an = 0;
        break;
      }
    printf("%d\n", an);
  }
}
