#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
char s[525][525], qy[525];
int a[525][525 + 300], q;
void pp(int x, int y) {
  for (int(i) = 1; (i) <= (int)(x); (i)++) {
    for (int(j) = 1; (j) <= (int)(y); (j)++) printf("%d ", a[i][j]);
    puts("");
  }
}
void Gaw() {
  int SZ = n + q;
  int fr = 0;
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    int j = -1, r = i;
    while (r <= n) {
      for (int k = i; k <= m; k++) {
        if (abs(a[k][r]) != 0) {
          j = k;
          break;
        }
      }
      if (j == -1)
        r++;
      else {
        for (int k = i; k <= m; k++) swap(a[k][i], a[k][r]);
        break;
      }
    }
    if (n < r) break;
    if (j == -1) {
      continue;
    }
    fr++;
    if (i != j)
      for (int k = i; k <= SZ; k++) swap(a[i][k], a[j][k]);
    for (int k = i + 1; k <= m; k++)
      if (k != i && a[k][i] != 0) {
        for (int p = SZ; p >= i; p--) {
          a[k][p] = a[i][p] * (5 - a[k][i]) % 5 + a[k][p] * a[i][i] % 5;
          a[k][p] %= 5;
        }
      }
  }
  int ans = fastPow(5, n - fr);
  for (int(i) = 1; (i) <= (int)(q); (i)++) {
    int ta = ans;
    for (int(j) = 1; (j) <= (int)(m); (j)++)
      if (a[j][n + i] != 0) {
        bool ok = 0;
        for (int(x) = 1; (x) <= (int)(n); (x)++)
          if (a[j][x] != 0) {
            ok = 1;
            break;
          }
        if (ok) continue;
        ta = 0;
        break;
      }
    printf("%d\n", ta);
  }
}
void fmain(int tid) {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%s", s[i] + 1);
  for (int(j) = 1; (j) <= (int)(m); (j)++) {
    for (int(i) = 1; (i) <= (int)(n); (i)++) {
      a[j][i] = s[i][j] - 'a';
    }
  }
  scanf("%d", &q);
  for (int(i) = 1; (i) <= (int)(q); (i)++) {
    scanf("%s", qy + 1);
    for (int(j) = 1; (j) <= (int)(m); (j)++) {
      a[j][n + i] = qy[j] - 'a';
    }
  }
  Gaw();
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
