#include <bits/stdc++.h>
using namespace std;
struct elem {
  int i1, i2, p1, p2, tipo;
  elem() {}
  elem(int i1, int i2) : i1(i1), i2(i2) { tipo = 0; }
  elem(int i1, int i2, int p1, int p2) : i1(i1), i2(i2), p1(p1), p2(p2) {
    tipo = 1;
  }
};
int inverso(int x) {
  if (x == 2) return 3;
  if (x == 3) return 2;
  return x;
}
vector<elem> lista;
const int limite = 505;
int m, n;
int t[limite][limite];
char buff[limite];
int b[limite];
void escribe() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << t[i][j] << ",";
    cout << endl;
  }
  cout << endl;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int j = 0; j < m; j++) {
    scanf("%s", buff);
    for (int i = 0; i < n; i++) t[i][j] = buff[i] - 'a';
  }
  int jlibres = 0;
  int itope;
  {
    int jj = 0;
    int i = 0;
    while (i < n and jj < m) {
      int ii = i;
      while (ii < n and t[ii][jj] == 0) ii++;
      if (ii == n) {
        jj++;
        jlibres++;
      } else {
        lista.push_back(elem(i, ii));
        for (int j = jj; j < m; j++) swap(t[i][j], t[ii][j]);
        for (int ii = i + 1; ii < n; ii++) {
          if (t[ii][jj]) {
            int p1 = -t[ii][jj];
            int p2 = t[i][jj];
            lista.push_back(elem(i, ii, p1, p2));
            for (int j = jj; j < m; j++)
              t[ii][j] = (t[ii][j] * p2 + t[i][j] * p1) % 5;
          }
        }
        i++;
        jj++;
      }
    }
    itope = i;
    jlibres += m - jj;
  }
  long long int sol = 1;
  for (int j = 0; j < jlibres; j++) sol = sol * 5 % int(1e9 + 7);
  int casos;
  scanf("%d", &casos);
  for (int cas = 0; cas < casos; cas++) {
    scanf("%s", buff);
    for (int i = 0; i < n; i++) b[i] = buff[i] - 'a';
    for (int k = 0; k < int(lista.size()); k++) {
      elem &e = lista[k];
      int i1 = e.i1;
      int i2 = e.i2;
      int p1 = e.p1;
      int p2 = e.p2;
      if (e.tipo == 0) {
        swap(b[i1], b[i2]);
      } else {
        b[i2] = (b[i2] * p2 + b[i1] * p1) % 5;
      }
    }
    bool error = false;
    for (int i = itope; i < n and not error; i++) error = b[i] != 0;
    if (error)
      printf("%d\n", 0);
    else
      printf("%d\n", int(sol));
  }
}
