#include <bits/stdc++.h>
using namespace std;
bool use[510], zero[510];
int did[510][510], cnt;
int mac[510][510], n, m, q, ans;
char s[510], b[510];
int inv[5] = {0, 1, 3, 2, 4};
int md5[200];
void Gauss() {
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++)
      if (mac[i][j]) {
        use[i] = 1;
        for (int k = 1; k <= m; k++)
          if (k != i && mac[k][j]) {
            did[i][k] = md5[mac[k][j] * inv[mac[i][j]]];
            for (int p = 1; p <= n; p++) {
              mac[k][p] -= md5[mac[i][p] * did[i][k]];
              if (mac[k][p] < 0) mac[k][p] += 5;
            }
          }
        break;
      }
  }
  for (int i = 1; i <= m; i++) {
    bool flag = 0;
    for (int j = 1; j <= n; j++)
      if (mac[i][j]) {
        flag = 1;
        break;
      }
    if (flag)
      cnt++;
    else
      zero[i] = 1;
  }
  for (int i = 1; i <= n - cnt; i++) ans = 5ll * ans % 1000000007;
}
int main() {
  scanf("%d%d", &n, &m);
  ans = 1;
  for (int i = 0; i <= 25; i++) md5[i] = i % 5;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) mac[j][i] = s[j] - 'a';
  }
  Gauss();
  scanf("%d", &q);
  while (q--) {
    scanf("%s", b + 1);
    for (int i = 1; i <= m; i++) b[i] -= 'a';
    for (int i = 1; i <= m; i++)
      if (use[i]) {
        for (int j = 1; j <= m; j++)
          if (j != i) {
            b[j] -= md5[b[i] * did[i][j]];
            if (b[j] < 0) b[j] += 5;
          }
      }
    bool flag = 0;
    for (int i = 1; i <= m; i++)
      if (zero[i] && b[i]) {
        flag = 1;
        break;
      }
    cout << (flag ? 0 : ans) << endl;
  }
  return 0;
}
