#include <bits/stdc++.h>
using namespace std;
const int B = 1e9 + 7, N = 510;
int n, m, q;
int inv[5] = {0, 1, 3, 2, 4};
char t[N];
int pw[N] = {1};
int a[N][N << 1];
void init() {
  for (int i = 1; i < N; ++i) {
    pw[i] = pw[i - 1] * 5ll % B;
  }
}
int solve(int m, int n, int ns) {
  int i, j, k, id, s;
  for (i = 0; i < n && k < m; ++i) {
    for (j = k; j < m; ++j)
      if (a[j][i]) break;
    if (j == m) {
    } else {
      for (id = 0; id < ns; ++id) swap(a[j][id], a[k][id]);
      for (j = k + 1; j < m; ++j) {
        s = a[j][i] * inv[a[k][i]] % 5;
        for (id = i; id < ns; ++id) {
          a[j][id] = (a[j][id] - a[k][id] * s + 100) % 5;
        }
      }
      ++k;
    }
  }
  return k;
}
int main() {
  init();
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", t);
    for (int j = 0; j < m; ++j) {
      a[j][i] = t[j] - 'a';
    }
  }
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%s", t);
    for (int j = 0; j < m; ++j) a[j][i + n] = t[j] - 'a';
  }
  int rk = solve(m, n, n + q);
  for (int i = 0; i < q; ++i) {
    int j;
    for (j = rk; j < m; ++j)
      if (a[j][i + n]) break;
    if (j < m)
      puts("0");
    else
      printf("%d\n", pw[n - rk]);
  }
  return 0;
}
