#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
  cout << str << " : " << t << endl;
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  int idx = str.find(',');
  cout << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cout << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cout << ", ";
    cout << *i;
  }
  cout << "]";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = (0); i <= (n - 1); ++i) {
    string s;
    cin >> s;
    for (int j = (0); j <= (m - 1); ++j) a[i][j] = s[j] - 'a';
  }
  sort((a).begin(), (a).end());
  int inv[5] = {0, 1, 3, 2, 4};
  for (int i = (1); i <= (n - 1); ++i) {
    for (int j = (0); j <= (i - 1); ++j) {
      int first = 0;
      while (first < m && a[j][first] == 0) ++first;
      if (first == m) continue;
      int count = (((5 - a[i][first]) % 5) * inv[a[j][first]]) % 5;
      for (int k = (0); k <= (m - 1); ++k) (a[i][k] += count * a[j][k]) %= 5;
    }
  }
  int ans = 1;
  for (int i = (0); i <= (n - 1); ++i) {
    int cnt = 0;
    for (int j = (0); j <= (m - 1); ++j) cnt += !a[i][j];
    if (cnt == m) ans = (ans * 5LL) % inf;
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    vector<int> b(m);
    for (int j = (0); j <= (m - 1); ++j) b[j] = s[j] - 'a';
    for (int j = (0); j <= (n - 1); ++j) {
      int first = 0;
      while (first < m && a[j][first] == 0) ++first;
      if (first == m) continue;
      int count = (((5 - b[first]) % 5) * inv[a[j][first]]) % 5;
      for (int k = (0); k <= (m - 1); ++k) (b[k] += count * a[j][k]) %= 5;
    }
    int count = 0;
    for (int i = (0); i <= (m - 1); ++i) count += !b[i];
    cout << (count == m ? ans : 0) << "\n";
  }
  return 0;
}
