#include <bits/stdc++.h>
using namespace std;
int a[1001][1001];
int ans = 0, cnt = 0;
char str[1001];
int p[1001];
int n, m, q;
int Inv[101] = {0, 1, 3, 2, 4};
const int mod = (int)1e9 + 7;
int ksm(int x, int y) {
  int sum = 1;
  for (; y; y >>= 1) {
    if (y & 1) sum = 1LL * sum * x % mod;
    x = 1LL * x * x % mod;
  }
  return sum;
}
void Print() {
  for (int i = 1; i <= m; puts(""), i++)
    for (int j = 1; j <= n + m; j++) printf("%d ", a[i][j]);
}
void gauss() {
  int beta = 1;
  for (int i = 1;; i++) {
    if (beta == n + 1) break;
    int idx = -1;
    for (int j = cnt + 1; j <= m; j++) {
      if (a[j][beta] == 0) continue;
      idx = j;
      break;
    }
    if (idx == -1) {
      ++beta;
      continue;
    }
    --ans;
    ++cnt;
    for (int j = 1; j <= n + m; j++) swap(a[cnt][j], a[idx][j]);
    for (int j = cnt + 1; j <= m; j++) {
      int tmp = a[j][beta] * Inv[a[cnt][beta]] % 5;
      for (int k = beta; k <= n + m; k++) {
        a[j][k] -= a[cnt][k] * tmp % 5;
        a[j][k] = (a[j][k] + 5) % 5;
      }
    }
    ++beta;
  }
}
int main() {
  scanf("%d %d", &n, &m);
  ans = n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", str + 1);
    for (int j = 1; j <= m; j++) {
      a[j][i] = str[j] - 'a';
      a[j][n + j] = 1;
    }
  }
  gauss();
  scanf("%d", &q);
  while (q--) {
    bool ok = false;
    scanf("%s", str + 1);
    for (int j = 1; j <= m; j++) p[j] = str[j] - 'a';
    for (int j = cnt + 1; j <= m; j++) {
      int tmp = 0;
      for (int k = n + 1; k <= n + m; k++) {
        tmp += a[j][k] * p[k - n] % 5;
        tmp %= 5;
      }
      if (tmp) {
        ok = true;
        break;
      }
    }
    if (ok)
      printf("0\n");
    else
      printf("%d\n", ksm(5, ans));
  }
  return 0;
}
