#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 10, mod = 5, INF = 0x3f3f3f3f;
int add(int a, int b) {
  if ((a += b) >= mod) a -= mod;
  return a < 0 ? a + mod : a;
}
int mul(int a, int b) { return 1ll * a * b % mod; }
int kpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a)) {
    if (b & 1) r = mul(r, a);
  }
  return r;
}
int a[maxn][maxn << 1], x[maxn], r, non[maxn];
int Gauss(int row, int col, int bnum) {
  r = 0;
  for (int c = 0; r < row && c < col; ++r, ++c) {
    int p = r;
    for (int i = r; i < row; ++i)
      if (a[i][c]) {
        p = i;
        break;
      }
    if (p != r)
      for (int i = c; i < col + bnum; ++i) swap(a[p][i], a[r][i]);
    if (!a[r][c]) {
      r--;
      continue;
    }
    int inv = kpow(a[r][c], mod - 2);
    for (int i = c; i < col + bnum; ++i) a[r][i] = mul(a[r][i], inv);
    for (int i = r + 1; i < row; ++i)
      if (a[i][c]) {
        int t = a[i][c];
        for (int j = c; j < col + bnum; ++j)
          a[i][j] = add(a[i][j], -mul(a[r][j], t));
      }
  }
  for (int i = r; i < row; ++i)
    for (int j = col; j < col + bnum; ++j)
      if (a[i][j]) non[j - col] = 1;
  return col - r;
}
char s[maxn][maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) scanf("%s", s[i]);
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < n; ++j) a[i][j] = s[j][i] - 'a';
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    scanf("%s", s[0]);
    for (int j = 0; j < m; ++j) a[j][n + i] = s[0][j] - 'a';
  }
  int fnum = Gauss(m, n, q);
  int M = 1e9 + 7, ans = 1;
  for (int i = 1; i <= fnum; ++i) ans = ans * 5ll % M;
  for (int i = 0; i < q; ++i) {
    if (non[i])
      printf("0\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
