#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long first) {
  return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;
}
inline int rd() {
  int first = 0;
  char p = getchar();
  while (p < '0' || p > '9') p = getchar();
  while (p >= '0' && p <= '9') first = first * 10 + p - '0', p = getchar();
  return first;
}
const int N = 510;
int n, m, q, A[N][2 * N], in[N];
char s[N];
int main() {
  for (int i = 0; i <= 4; ++i) in[i] = i * i * i % 5;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; ++j) A[j][i] = s[j] - 'a';
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; ++j) A[j][i + n] = s[j] - 'a';
  }
  int r = 0;
  for (int i = 1; i <= n; ++i) {
    int p = r;
    while (!A[p][i] && p <= m) ++p;
    if (p > m) continue;
    if (p != r)
      for (int j = 1; j <= n + q; ++j) swap(A[p][j], A[r][j]);
    for (int j = 1; j <= m; ++j)
      if (j != r && A[j][i]) {
        int t = A[j][i] * in[A[r][i]] % 5;
        for (int k = 1; k <= n + q; ++k)
          A[j][k] = (A[j][k] - t * A[r][k] + 25) % 5;
      }
    ++r;
  }
  for (int i = 1; i <= q; ++i) {
    int ans = qpow(5, n - r);
    for (int j = 1; j <= m; ++j)
      if (A[j][i + n]) {
        int ok = 0;
        for (int k = 1; k <= n; ++k)
          if (A[j][k]) ok = 1;
        if (!ok) ans = 0;
      }
    printf("%d\n", ans);
  }
}
