#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int MOD = 1000000007;
int n, m, qn, inv[5], a[N][N << 1];
char s[N];
int exgcd(int a, int b, int& x, int& y) {
  if (!b) return x = 1, y = 0, a;
  int d = exgcd(b, a % b, y, x);
  return y -= a / b * x, d;
}
int main() {
  int i, j, k, x, y;
  for (i = 1; i < 5; ++i) {
    exgcd(i, 5, x, y);
    inv[i] = (x % 5 + 5) % 5;
  }
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (j = 1; j <= m; ++j) a[j][i] = s[j] - 'a';
  }
  scanf("%d", &qn);
  for (i = 1; i <= qn; ++i) {
    scanf("%s", s + 1);
    for (j = 1; j <= m; ++j) a[j][i + n] = s[j] - 'a';
  }
  int row = 1;
  int ans = 1;
  for (i = 1; i <= n; ++i) {
    for (k = j = row; j <= m; ++j)
      if (a[j][i] > a[k][i]) k = j;
    if (!a[k][i]) {
      ans = (long long)ans * 5 % MOD;
      continue;
    }
    if (k != row)
      for (j = i; j <= n + qn; ++j) swap(a[row][j], a[k][j]);
    for (j = 1; j <= m; ++j)
      if (j != row) {
        if (!a[j][i]) continue;
        x = a[j][i] * inv[a[row][i]] % 5;
        for (k = i; k <= n + qn; ++k)
          a[j][k] = (a[j][k] - x * a[row][k] % 5 + 5) % 5;
      }
    ++row;
  }
  int low = 0;
  for (i = m; i; --i) {
    for (j = 1; j <= n; ++j)
      if (a[i][j]) {
        low = i;
        break;
      }
    if (low) break;
  }
  for (i = 1; i <= qn; ++i) {
    for (j = m; j; --j)
      if (a[j][i + n]) break;
    if (j > low)
      puts("0");
    else
      printf("%d\n", ans);
  }
  return 0;
}
