#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:1048576")
using namespace std;
int IT_MAX = 1 << 18;
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const double ERR = 1e-10;
int minv[5] = {0, 1, 3, 2, 4};
int A[505][505];
int piv[505];
int qu[505];
int ans[505];
char u[505];
int main() {
  int N, M, Q, i, j, k, l, p;
  scanf("%d %d", &N, &M);
  for (i = 1; i <= N; i++) {
    scanf("%s", u + 1);
    for (j = 1; j <= M; j++) A[i][j] = u[j] - 'a';
  }
  for (i = 1, j = 1; i <= N && j <= M; j++) {
    for (p = i; p <= N; p++)
      if (A[p][j]) break;
    if (p > N) continue;
    for (k = j; k <= M; k++) swap(A[i][k], A[p][k]);
    piv[i] = j;
    for (k = i + 1; k <= N; k++) {
      int t = A[k][j] * minv[A[i][j]] % 5;
      for (l = j; l <= M; l++) A[k][l] = (A[k][l] + (5 - t) * A[i][l]) % 5;
    }
    i++;
  }
  int pc = i - 1;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%s", u + 1);
    for (j = 1; j <= M; j++) qu[j] = u[j] - 'a';
    for (i = 1; i <= M; i++) ans[i] = 0;
    for (i = 1; i <= pc; i++) {
      int x = piv[i];
      int t = (qu[x] - ans[x] + 5) * minv[A[i][x]] % 5;
      for (j = 1; j <= M; j++) ans[j] = (ans[j] + A[i][j] * t) % 5;
    }
    for (i = 1; i <= M; i++)
      if (ans[i] != qu[i]) break;
    long long ans = 1;
    if (i <= M) ans = 0;
    for (i = 1; i <= N - pc; i++) ans = (ans * 5) % MOD;
    printf("%lld\n", ans);
  }
  return 0;
}
