#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int a[maxn][maxn], b[maxn];
int n, m, cnt;
const int mod = 1e9 + 7;
bool sfind() {
  int inv[5] = {0, 1, 3, 2, 4};
  for (int j = 0; j < cnt; j++)
    for (int k = 0; k < m; k++)
      if (a[j][k]) {
        int t = b[k] * inv[a[j][k]] % 5;
        for (int l = 0; l < m; l++) b[l] = (b[l] - t * a[j][l] % 5 + 5) % 5;
        break;
      }
  bool flag = 0;
  for (int i = 0; i < m; i++) flag |= (b[i] > 0);
  return flag;
}
int main() {
  int q;
  char ss[maxn];
  cnt = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", &ss);
    for (int i = 0; i < m; i++) b[i] = ss[i] - 'a';
    bool flag = sfind();
    if (flag) {
      for (int j = 0; j < m; j++) a[cnt][j] = b[j];
      cnt++;
    }
  }
  long long res = 1;
  for (int i = 0; i < n - cnt; i++) res = 5LL * res % mod;
  scanf("%d", &q);
  while (q--) {
    scanf("%s", &ss);
    for (int i = 0; i < m; i++) b[i] = ss[i] - 'a';
    bool flag = sfind();
    printf("%lld\n", flag == 0 ? res : 0);
  }
}
