#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-12;
const int MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 5e2 + 4;
const int maxm = 1e3 + 4;
int Inv[5] = {0, 1, 3, 2, 4}, t[maxn];
inline void rule(int& x) { x = (x % 5 + 5) % 5; }
struct Matrix {
  int r, c, lst;
  int m[maxn][maxn], mark[maxn];
  vector<int> a[maxn];
  Matrix(int _r, int _c = 0) : r(_r), c(!_c ? _r : _c) {
    memset(m, 0, sizeof m);
    for (int i = 1; i <= r; ++i) a[i].resize(r + 1), a[i][i] = 1;
  }
  int Guass_elimination() {
    int ret = 0, t = 1;
    for (int i = 1; i <= min(r, c) && t <= c; ++i) {
      int pos = i;
      for (int j = i + 1; j <= r; ++j)
        if (fabs(m[j][t]) > fabs(m[pos][t])) pos = j;
      if (pos != i) {
        for (int j = 1; j <= c; ++j) swap(m[i][j], m[pos][j]);
        swap(a[pos], a[i]);
      }
      if (m[i][t] == 0) {
        t++;
        i--;
        continue;
      }
      mark[i] = t;
      lst = i;
      ret++;
      int inv = Inv[m[i][t]];
      for (int j = i + 1; j <= r; ++j)
        if (m[j][t]) {
          int x = m[j][t] * inv % 5;
          for (int k = t; k <= c; ++k) {
            m[j][k] -= x * m[i][k];
            rule(m[j][k]);
          }
          for (int k = 1; k <= r; ++k) {
            a[j][k] -= x * a[i][k];
            rule(a[j][k]);
          }
        }
      t++;
    }
    return c - ret;
  }
  void print() {
    for (int i = 1; i <= r; ++i) {
      for (int j = 1; j <= c; ++j) printf("%3d", m[i][j]);
      puts("");
    }
  }
  void aprint() {
    for (int i = 1; i <= r; ++i) {
      for (int j = 1; j <= r; ++j) printf("%3d", a[i][j]);
      puts("");
    }
  }
  bool check() {
    for (int i = lst + 1; i <= r; ++i) {
      int ans = 0;
      for (int j = 1; j <= r; ++j) ans += a[i][j] * t[j];
      if (ans % 5) return false;
    }
    return true;
  }
};
int n, m;
char s[maxn];
int main() {
  int ik, i, j, k, kase;
  scanf("%d%d", &n, &m);
  Matrix mat(m, n);
  for (i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (j = 1; j <= m; ++j) mat.m[j][i] = s[j] - 'a';
  }
  int ret = mat.Guass_elimination();
  int ans = 1;
  for (int i = 1; i <= ret; ++i) ans = 1LL * ans * 5 % MOD;
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%s", s + 1);
    for (j = 1; j <= m; ++j) t[j] = s[j] - 'a';
    if (mat.check())
      printf("%d\n", ans);
    else
      puts("0");
  }
  return 0;
}
