#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXEQ = 500;
const int MAXVAR = 500;
const int MAXQ = 300;
int neq, nvar, nq;
char s[MAXVAR + 1];
int nr, nc;
int A[MAXEQ][MAXVAR + MAXQ];
int inv[5];
int gaussjord() {
  int r = 0, c = 0;
  while (r < nr && c < neq) {
    {
      int rr = r;
      while (rr < nr && A[rr][c] == 0) ++rr;
      if (rr >= nr) {
        ++c;
        continue;
      }
      if (rr != r)
        for (int cc = (c); cc < (nc); ++cc) swap(A[r][cc], A[rr][cc]);
    }
    int mlt = inv[A[r][c]];
    for (int cc = (c); cc < (nc); ++cc) A[r][cc] = A[r][cc] * mlt % 5;
    for (int rr = (r + 1); rr < (nr); ++rr) {
      int t = A[rr][c];
      for (int cc = (c); cc < (nc); ++cc)
        A[rr][cc] = (A[rr][cc] + (5 - t) * A[r][cc]) % 5;
    }
    ++r, ++c;
  }
  --r;
  int ndim = 0;
  while (r >= 0) {
    c = 0;
    while (A[r][c] == 0) ++c;
    assert(A[r][c] == 1);
    for (int rr = (0); rr < (r); ++rr) {
      int t = A[rr][c];
      for (int cc = (c); cc < (nc); ++cc)
        A[rr][cc] = (A[rr][cc] + (5 - t) * A[r][cc]) % 5;
    }
    ++ndim;
    --r;
  }
  return ndim;
}
void run() {
  inv[1] = 1;
  inv[2] = 3;
  inv[3] = 2;
  inv[4] = 4;
  scanf("%d%d", &neq, &nvar);
  for (int i = (0); i < (neq); ++i) {
    scanf("%s", s);
    for (int j = (0); j < (nvar); ++j) A[j][i] = s[j] - 'a';
  }
  scanf("%d", &nq);
  for (int i = (0); i < (nq); ++i) {
    scanf("%s", s);
    for (int j = (0); j < (nvar); ++j) A[j][neq + i] = s[j] - 'a';
  }
  nr = nvar, nc = neq + nq;
  int ndim = gaussjord();
  int ans = 1;
  for (int i = (0); i < (neq - ndim); ++i)
    ans = (long long)ans * 5 % 1000000007;
  for (int i = (0); i < (nq); ++i) {
    bool ok = true;
    for (int j = (ndim); j < (nvar); ++j)
      if (A[j][neq + i] != 0) ok = false;
    printf("%d\n", ok ? ans : 0);
  }
}
int main() {
  run();
  return 0;
}
