#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500;
const int MOD = 1000000007;
int n, m, q;
int p[MAXN + 5][MAXN + 5];
int bio[MAXN + 5];
int pos;
int t[MAXN + 5];
int cnt;
int qmat[MAXN + 5][MAXN + 5];
char c[MAXN + 5];
void swapaj(int a, int b) {
  for (int i = (0), _for = (m); i < _for; ++i) swap(p[a][i], p[b][i]);
}
void rem(int a, int b) {
  int inv = 0;
  for (int i = (0), _for = (5); i < _for; ++i)
    if (p[a][pos] * i % 5 == p[b][pos]) inv = i;
  for (int i = (0), _for = (m); i < _for; ++i)
    p[b][i] = ((p[b][i] - p[a][i] * inv) % 5 + 5) % 5;
}
void rem2(int a, int b) {
  int inv = 0;
  for (int i = (0), _for = (5); i < _for; ++i)
    if (p[a][pos] * i % 5 == qmat[b][pos]) inv = i;
  for (int i = (0), _for = (m); i < _for; ++i)
    qmat[b][i] = ((qmat[b][i] - p[a][i] * inv) % 5 + 5) % 5;
}
bool eq0(int a) {
  for (int i = (0), _for = (m); i < _for; ++i)
    if (qmat[a][i]) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0), _for = (n); i < _for; ++i) {
    scanf("%s", c);
    for (int j = (0), _for = (m); j < _for; ++j) p[i][j] = (int)c[j] - 'a';
  }
  scanf("%d", &q);
  for (int i = (0), _for = (q); i < _for; ++i) {
    scanf("%s", c);
    for (int j = (0), _for = (m); j < _for; ++j) qmat[i][j] = (int)c[j] - 'a';
  }
  for (int i = 0; i < n; ++i, pos++) {
    if (pos == m) break;
    if (!p[i][pos])
      for (int j = i + 1; j < n && !p[i][pos]; ++j)
        if (p[j][pos]) swapaj(i, j);
    if (!p[i][pos]) {
      i--;
      continue;
    }
    cnt++;
    for (int j = (0), _for = (n); j < _for; ++j)
      if (i != j) rem(i, j);
    for (int j = (0), _for = (q); j < _for; ++j) rem2(i, j);
  }
  int sol = 1;
  for (int i = (0), _for = (n - cnt); i < _for; ++i)
    sol = ((long long)sol * 5) % MOD;
  for (int i = (0), _for = (q); i < _for; ++i) printf("%d\n", eq0(i) ? sol : 0);
  return 0;
}
