#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long n, m, q, a[501][501], b[501][501], r[501], p[501], t, ans = 1;
bool vis[501];
string s;
void gauss() {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j])
        if (!vis[j]) {
          vis[j] = true, ++t;
          for (int k = 1; k <= m; ++k) b[j][k] = a[i][k];
          break;
        } else if (a[i][j]) {
          int t = 0;
          while (a[i][j]) (a[i][j] += b[j][j]) %= 5, ++t;
          for (int k = 1; k <= m; ++k)
            if (j != k) (a[i][k] += b[j][k] * t) %= 5;
        }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m, ans = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    for (int j = 1; j <= m; ++j) a[i][j] = s[j - 1] - 'a';
  }
  cin >> q, gauss();
  for (int i = t; i < n; ++i) (ans *= 5) %= mod;
  while (q--) {
    cin >> s, memset(p, 0, sizeof p);
    for (int i = 1; i <= m; ++i) r[i] = s[i - 1] - 'a';
    bool flag = false;
    for (int i = 1; i <= m; ++i) {
      if (p[i] != r[i]) {
        if (!b[i][i]) {
          flag = true;
          break;
        }
        int t = 0;
        while (p[i] != r[i]) (p[i] += b[i][i]) %= 5, ++t;
        for (int j = 1; j <= m; ++j)
          if (i != j) (p[j] += b[i][j] * t) %= 5;
      }
    }
    if (flag)
      cout << 0 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
