#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 30010;
const int MX = 1000000;
const int MOD = 1000000007;
int n, m, q;
char g[1010][510];
bool imp[510];
vector<vector<int> > mat;
long long fastPow(long long a, long long b, long long p) {
  if (!b) return 1ll;
  long long res = fastPow(a, b / 2, p);
  res = (res * res) % p;
  if (b & 1) return (res * a) % p;
  return res % p;
}
int inverse(int a) { return fastPow(a, 5 - 2, 5); }
void insert(vector<int> &v) {
  int idx = 0;
  for (int i = 0; i < mat.size(); ++i) {
    int f = 0;
    while (idx < v.size() && !v[idx]) idx++;
    if (idx == n) break;
    while (f < mat[i].size() && !mat[i][f]) f++;
    if (idx > f) continue;
    if (idx < f) {
      mat.insert(mat.begin() + i, v);
      return;
    }
    if (idx == f) {
      long long r = v[idx] * inverse(mat[i][idx]);
      for (int j = 0; j < v.size(); ++j) {
        v[j] = (v[j] - (mat[i][j] * r) % 5 + 5) % 5;
      }
    }
  }
  if (mat.size()) {
    bool eq = true;
    bool z = true;
    for (int i = 0; i < n; ++i) {
      if (v[i] != mat.back()[i]) eq = false;
      if (v[i]) z = false;
    }
    if (z) {
      for (int i = n; i < n + q; ++i) {
        if (v[i]) imp[i - n] = true;
      }
    }
    if (eq) return;
  }
  mat.push_back(v);
}
int solve(int idx) {
  if (imp[idx]) return 0;
  bool z = true;
  for (int i = 0; i < n; ++i) {
    if (mat.back()[i]) z = false;
  }
  if (z && mat.back()[n + idx]) return 0;
  return fastPow(5, n - (mat.size() - z), MOD);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", g[i]);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%s", g[i + n]);
  }
  for (int i = 0; i < m; ++i) {
    vector<int> r;
    for (int j = 0; j < n + q; ++j) {
      r.push_back(g[j][i] - 'a');
    }
    insert(r);
  }
  for (int i = 0; i < q; ++i) {
    printf("%d\n", solve(i));
  }
  return 0;
}
