#include <bits/stdc++.h>
std::string input() {
  static char buf[1000];
  scanf("%s", buf);
  return std::string(buf);
}
int main() {
  int inv[5] = {0, 1, 3, 2, 4};
  int n, m;
  std::cin >> n >> m;
  static int a[500][1000];
  for (int i = 0; i < m; i++) {
    a[i][i + n] = 1;
  }
  for (int i = 0; i < n; i++) {
    std::string s = input();
    for (int j = 0; j < m; j++) {
      a[j][i] = s[j] - 'a';
    }
  }
  const int h = m;
  const int w = n + m;
  int r = 0;
  for (int j = 0; j < n && r < h; j++) {
    int p = r;
    for (int i = r; i < h; i++) {
      if (a[i][j] != 0) {
        p = i;
        break;
      }
    }
    std::swap(a[p], a[r]);
    if (a[r][j] == 0) continue;
    for (int jj = j + 1; jj < w; jj++) {
      a[r][jj] = a[r][jj] * inv[a[r][j]] % 5;
    }
    a[r][j] = 1;
    for (int ii = 0; ii < h; ii++) {
      if (ii != r) {
        for (int jj = j + 1; jj < w; jj++) {
          a[ii][jj] += 2500 - a[ii][j] * a[r][jj];
          a[ii][jj] %= 5;
        }
        a[ii][j] = 0;
      }
    }
    r++;
  }
  int q;
  std::cin >> q;
  while (q--) {
    std::string b = input();
    std::vector<int> v(m);
    for (int i = 0; i < m; i++) {
      v[i] = b[i] - 'a';
    }
    std::vector<int> u(m);
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        u[i] += a[i][n + j] * v[j];
      }
      u[i] %= 5;
    }
    bool any = false;
    for (int i = r; i < m; i++) {
      if (u[i] != 0) {
        any = true;
      }
    }
    constexpr long long MOD2 = 1e9 + 7;
    long long ans = 1;
    for (int i = r; i < n; i++) {
      ans *= 5;
      ans %= MOD2;
    }
    if (any) {
      puts("0");
      continue;
    }
    printf("%d\n", (int)ans);
  }
}
