#include <bits/stdc++.h>
const long long M = 1000000007;
using namespace std;
long long n, m;
vector<long long> inv = {0, 1, 3, 2, 4};
vector<vector<long long>> A;
vector<long long> p;
long long power(long long a, long long n) {
  long long r = 1;
  while (n) {
    if (n & 1) {
      n--;
      r *= a;
      r %= M;
    } else {
      n >>= 1;
      a *= a;
      a %= M;
    }
  }
  return r;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m;
  vector<string> s;
  s.resize(n);
  for (long long i = 0; i < n; i++) cin >> s[i];
  A.resize(n, vector<long long>(m));
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) A[i][j] = s[i][j] - 'a';
  long long rank = 0;
  for (long long i = 0; i < m; i++) {
    long long j0 = -1;
    for (long long j = rank; j < n; j++) {
      if (A[j][i] != 0) j0 = j;
    }
    if (j0 == -1) continue;
    if (j0 > rank) swap(A[rank], A[j0]);
    p.push_back(i);
    long long mod = inv[A[rank][i]];
    for (long long j = 0; j < m; j++) A[rank][j] = (A[rank][j] * mod) % 5;
    for (int i0 = rank + 1; i0 < n; i0++) {
      if (i0 == rank) continue;
      int lambda = A[i0][i];
      for (int j = 0; j < m; j++) {
        A[i0][j] += 5 - (lambda * A[rank][j]) % 5;
        A[i0][j] %= 5;
      }
    }
    rank++;
  }
  long long q;
  cin >> q;
  long long r5 = power(5, n - rank);
  for (long long g = 0; g < q; g++) {
    string ss;
    cin >> ss;
    vector<long long> b(m);
    for (long long i = 0; i < m; i++) b[i] = ss[i] - 'a';
    bool G = true;
    if (rank < m) {
      for (long long i = 0; i < rank; i++) {
        long long mod = b[p[i]];
        for (long long j = 0; j < m; j++) {
          b[j] += 25 - A[i][j] * mod;
          b[j] %= 5;
        }
      }
      for (long long j = 0; j < m; j++)
        if (b[j]) G = false;
    }
    if (G)
      cout << r5 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
