#include <bits/stdc++.h>
using namespace std;
int f[505][505], b[505], d[505];
int p[50], inv[5];
char s[505];
int main() {
  int n, m, i, j, k, r;
  scanf("%d%d", &n, &m);
  for (i = 0; i < 50; i++) p[i] = i % 5;
  inv[0] = inv[1] = 1;
  for (i = 2; i < 5; i++) inv[i] = p[(5 - 5 / i) * inv[5 % i]];
  for (i = 0, r = 0; i < n; i++) {
    scanf("%s", s);
    for (j = 0; j < m; j++) b[j] = s[j] - 'a';
    for (k = 0; k < r; k++) {
      if (b[d[k]]) {
        int u = p[b[d[k]] * inv[f[k][d[k]]]];
        for (int l = 0; l < m; l++) b[l] = p[b[l] - u * f[k][l] + 25];
      }
    }
    for (k = 0; k < m; k++) {
      if (b[k]) {
        for (int l = 0; l < m; l++) f[r][l] = b[l];
        d[r++] = k;
        break;
      }
    }
  }
  int ans = 1;
  for (i = 0; i < n - r; i++) ans = 5LL * ans % 1000000007;
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%s", s);
    for (j = 0; j < m; j++) b[j] = s[j] - 'a';
    for (k = 0; k < r; k++) {
      if (b[d[k]]) {
        int u = p[b[d[k]] * inv[f[k][d[k]]]];
        for (int l = 0; l < m; l++) b[l] = p[b[l] - u * f[k][l] + 25];
      }
    }
    for (k = 0; k < m; k++) {
      if (b[k]) break;
    }
    if (k == m)
      printf("%d\n", ans);
    else
      printf("0\n");
  }
  return 0;
}
