#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7, max_col = 805;
int qpow(int a, int pos, int p) {
  int pa = a, rt = 1;
  for (; pos; pos >>= 1, pa = pa * 1ll * pa % p)
    if (pos & 1) rt = pa * 1ll * rt % p;
  return rt;
}
typedef class Matrix {
 public:
  int col, row;
  int a[505][max_col];
  bool zero[505];
  int guass(int n) {
    int r = 0;
    memset(zero, true, sizeof(bool) * row);
    for (int i = 0, cur = -1; r < row && i < n; i++, cur = -1) {
      for (int j = r; j < row && cur == -1; j++)
        if (a[j][i]) cur = j;
      if (cur == -1) continue;
      zero[r] = false;
      if (cur != i)
        for (int j = 0; j < col; j++) swap(a[r][j], a[cur][j]);
      for (int j = 0, x, y; j < row; j++) {
        if (j == r) continue;
        x = a[r][i], y = a[j][i];
        for (int k = 0; k < col; k++) {
          a[j][k] = (a[j][k] * x - a[r][k] * y) % 5;
          if (a[j][k] < 0) a[j][k] += 5;
        }
      }
      r++;
    }
    return r;
  }
  int* operator[](int p) { return a[p]; }
} Matrix;
int n, m, q;
Matrix mat;
char buf[505];
inline void init() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", buf);
    for (int j = 0; j < m; j++) mat[j][i] = (buf[j] - 'a');
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s", buf);
    for (int j = 0; j < m; j++) mat[j][n + i] = (buf[j] - 'a');
  }
}
int ans = 0;
bool hassol[305];
inline void solve() {
  mat.row = m, mat.col = n + q;
  int r = mat.guass(n);
  ans = qpow(5, n - r, M);
  memset(hassol, true, sizeof(bool) * q);
  for (int i = 0; i < m; i++)
    if (mat.zero[i])
      for (int j = 0; j < q; j++)
        if (mat[i][n + j]) hassol[j] = false;
  for (int i = 0; i < q; i++) printf("%d\n", (hassol[i]) ? (ans) : (0));
}
int main() {
  init();
  solve();
  return 0;
}
