#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
long long fpow(long long a, long long b) {
  a %= MOD;
  if (b == 0) return 1;
  long long res = fpow(a * a, b / 2);
  if (b & 1) res *= a;
  return res % MOD;
}
long long inv(long long x, int base) { return x * x * x % base; }
const int BASE = 5;
vector<int> guass(vector<vector<int>>& mat) {
  int n = (int)mat.size();
  int m = (int)mat[0].size();
  vector<int> where(m, -1);
  for (int col = 0, row = 0; col < m && row < n; ++col) {
    int cur = row;
    for (int i = row; i < n; ++i)
      if (mat[i][col] > mat[cur][col]) cur = i;
    if (mat[cur][col] == 0) continue;
    where[col] = row;
    swap(mat[row], mat[cur]);
    int c = mat[row][col];
    for (int i = 0; i < m; ++i) (mat[row][i] *= inv(c, BASE)) %= BASE;
    for (int i = 0; i < n; ++i) {
      if (i == row) continue;
      int d = mat[i][col];
      for (int j = 0; j < m; ++j) {
        mat[i][j] -= d * mat[row][j] % BASE;
        if (mat[i][j] < 0) mat[i][j] += BASE;
      }
    }
    ++row;
  }
  return where;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> mat(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < m; ++j) mat[i][j] = s[j] - 'a';
  }
  vector<int> where = guass(mat);
  int ind_cnt = n - m + count(where.begin(), where.end(), -1);
  int ans = fpow(5, ind_cnt);
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    vector<int> v(m);
    for (int i = 0; i < m; ++i) v[i] = s[i] - 'a';
    bool ok = true;
    for (int i = 0; i < m; ++i) {
      if (v[i] == 0) continue;
      int d = v[i];
      int idx = where[i];
      if (idx == -1) {
        ok = false;
        break;
      }
      for (int j = 0; j < m; ++j) {
        v[j] -= d * mat[idx][j] % 5;
        if (v[j] < 0) v[j] += 5;
      }
    }
    cout << (ok ? ans : 0) << "\n";
  }
}
