#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, q;
long long a[510][810], ans, inv[5];
char s[510];
long long qpow(long long x, long long k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = res * x % mod;
    x = x * x % mod;
    k >>= 1;
  }
  return res;
}
void print() {
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) cout << a[i][j] << " ";
    cout << "| ";
    for (int j = n + 1; j <= n + q; j++) cout << a[i][j] << " ";
    cout << endl;
  }
}
int main() {
  for (int i = 1; i < 5; i++) inv[i] = i * i * i % 5;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) a[j][i] = s[j] - 'a';
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) a[j][i + n] = s[j] - 'a';
  }
  for (int i = 1, pos = 1; pos <= n; i++) {
    while (pos <= n) {
      for (int j = i + 1; j <= m; j++)
        if (a[j][pos] > 0) swap(a[j], a[i]);
      if (a[i][pos]) break;
      pos++;
    }
    if (pos > n) {
      ans = qpow(5, n - i + 1);
      break;
    }
    for (int j = i + 1; j <= m; j++)
      if (a[j][pos] != 0) {
        long long t = a[j][pos] * inv[a[i][pos]] % 5;
        for (int k = pos; k <= n + q; k++)
          a[j][k] = ((a[j][k] - t * a[i][k]) % 5 + 5) % 5;
      }
  }
  for (int i = n + 1; i <= n + q; i++) {
    long long temp = ans;
    for (int j = 1, cnt = 0; j <= m; j++, cnt = 0) {
      for (int k = 1; k <= n; k++) cnt += a[j][k] > 0;
      if (!cnt && a[j][i]) temp = 0;
    }
    cout << temp << endl;
  }
  return 0;
}
