#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXN = 505;
const int MAXM = 505;
int n, m, q, g[MAXN][MAXM], si[MAXN], v[MAXM], inv[5];
char s[MAXM], p[MAXM];
int main() {
  scanf("%d %d", &n, &m);
  inv[1] = 1;
  inv[2] = 3;
  inv[3] = 2;
  inv[4] = 4;
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; j < m; j++) g[i][j] = s[j] - 'a';
  }
  int b = 0;
  for (int i = 0; i < m; i++) {
    bool found = false;
    for (int j = b; j < n; j++)
      if (g[j][i] != 0) {
        found = true;
        for (int k = 0; k < m; k++) swap(g[j][k], g[b][k]);
        break;
      }
    if (found) {
      si[b] = i;
      for (int j = b + 1; j < n; j++)
        if (g[j][i] != 0) {
          int f = (g[j][i] * inv[g[b][i]]) % 5;
          for (int k = b; k < m; k++)
            g[j][k] = (g[j][k] - f * g[b][k] + 25) % 5;
        }
      b++;
    }
  }
  long long r = 1;
  for (int i = 0; i < n - b; i++) r = (r * 5) % MOD;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s", p);
    for (int j = 0; j < m; j++) v[j] = p[j] - 'a';
    for (int j = 0; j < b; j++)
      if (v[si[j]] != 0) {
        int f = (inv[g[j][si[j]]] * v[si[j]]) % 5;
        for (int k = si[j]; k < m; k++) v[k] = (v[k] - f * g[j][k] + 25) % 5;
      }
    bool ok = true;
    for (int j = 0; j < m; j++)
      if (v[j] != 0) ok = false;
    if (ok)
      printf("%I64d\n", r);
    else
      printf("0\n");
  }
  return 0;
}
