#include <bits/stdc++.h>
const int N = 500 + 10;
const int MOD = 1e9 + 7;
int n, m, q;
int prod = 1;
char b[N][N];
char s[N];
void ins() {
  int i, j;
  for (i = 1; i <= int(m); i++) s[i] -= 'a';
  for (i = int(m); i; i--) {
    if (s[i]) {
      if (!b[i][i]) {
        memcpy(b[i], s, sizeof(s));
        return;
      }
      while (s[i])
        for (j = 1; j <= int(i); j++) s[j] = (s[j] + 5 - b[i][j]) % 5;
    }
  }
  prod = prod * 5LL % MOD;
}
int query() {
  int i, j;
  for (i = 1; i <= int(m); i++) s[i] -= 'a';
  for (i = int(m); i; i--) {
    if (s[i]) {
      if (!b[i][i]) return 0;
      while (s[i])
        for (j = 1; j <= int(i); j++) s[j] = (s[j] + 5 - b[i][j]) % 5;
    }
  }
  return prod;
}
int main() {
  int i;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= int(n); i++) {
    scanf("%s", s + 1);
    ins();
  }
  scanf("%d", &q);
  for (i = 1; i <= int(q); i++) {
    scanf("%s", s + 1);
    printf("%d\n", query());
  }
  return 0;
}
