#include <bits/stdc++.h>
using namespace std;
inline int Mod(int a) {
  while (a >= 5) a -= 5;
  while (a < 0) a += 5;
  return a;
}
inline int Inv(int a) {
  static const int inv[] = {0, 1, 3, 2, 4};
  return inv[a];
}
inline vector<int> Mul(const vector<int>& a, const vector<vector<int>>& b) {
  int n(a.size());
  vector<int> res(n, 0);
  for (int i(0); i < n; ++i)
    for (int j(0); j < n; ++j) res[j] += Mod(a[i] * b[i][j]);
  return res;
}
struct Operation {
  enum Type {
    Divide,
    Subtract,
    Swap,
  } type;
  int i, j, c;
  void Do(vector<int>& b) const noexcept {
    switch (type) {
      case Divide:
        b[i] = Mod(b[i] * Inv(c));
        break;
      case Subtract:
        b[j] = Mod(b[j] - b[i] * c);
        break;
      case Swap:
        swap(b[i], b[j]);
    }
  }
};
inline vector<Operation> Gauss(vector<vector<int>>& a, int& rng) {
  rng = 0;
  int n(a.size()), m(a[0].size());
  int j(0);
  vector<Operation> ops;
  for (int i(0); j < m and i < n; ++i) {
    for (int k(i + 1); k < n; ++k)
      if (a[k][j]) {
        a[i].swap(a[k]);
        ops.push_back({Operation::Swap, i, k});
        break;
      }
    if (!a[i][j]) {
      ++j;
      --i;
      continue;
    }
    ++rng;
    ops.push_back({Operation::Divide, i, -1, a[i][j]});
    for (int k(m - 1); k >= j; --k) a[i][k] = Mod(a[i][k] * Inv(a[i][j]));
    for (int k(i + 1); k < n; ++k) {
      ops.push_back({Operation::Subtract, i, k, a[k][j]});
      for (int l(m - 1); l >= j; --l) {
        a[k][l] = Mod(a[k][l] - a[k][j] * a[i][l]);
      }
    }
  }
  return ops;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string s;
  vector<vector<int>> matrix(m, vector<int>(n));
  for (int i(0); i < n; ++i) {
    cin >> s;
    for (int j(0); j < m; ++j) matrix[j][i] = s[j] - 'a';
  }
  int rng;
  auto ops(Gauss(matrix, rng));
  int64_t ans(1);
  for (int i(0); i < n - rng; ++i) ans = ans * 5 % (1000000007);
  int q;
  cin >> q;
  vector<int> b(m);
  while (q--) {
    cin >> s;
    for (int i(0); i < m; ++i) b[i] = s[i] - 'a';
    for (auto op : ops) op.Do(b);
    bool ok(true);
    for (int i(rng); i < m; ++i)
      if (b[i]) {
        ok = false;
        break;
      }
    if (ok)
      cout << ans << '\n';
    else
      cout << "0\n";
  }
}
