#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
template <typename T>
int gaussianElimination(vector<vector<T>> &A, int var = -1) {
  int N = A.size(), M = A[0].size();
  if (var < 0) var = min(N, M);
  int k = 0, rank = var;
  for (int i = 0; i < var; i++) {
    int v = -1;
    for (int j = k; j < N && v == -1; j++)
      if (A[j][i] != 0) v = j;
    if (v == -1) {
      rank--;
      continue;
    }
    swap(A[k], A[v]);
    T x = T(1) / A[k][i];
    for (int j = 0; j < M; j++) A[k][j] = A[k][j] * x;
    for (int j = k + 1; j < N; j++) {
      T y = A[j][i];
      for (int h = M - 1; h >= i; h--) A[j][h] = A[j][h] - A[k][h] * y;
    }
    k++;
  }
  return rank;
}
template <typename T>
void print(vector<vector<T>> &A) {
  int N = A.size(), M = A[0].size();
  for (int y = 0; y < N; y++) {
    for (int x = 0; x < M; x++) cout << A[y][x] << "\t";
    cout << endl;
  }
  cout << endl;
}
template <int MOD>
struct ModInt {
  static const int Mod = MOD;
  unsigned x;
  ModInt() : x(0) {}
  ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
  ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
  int get() const { return (int)x; }
  ModInt &operator+=(ModInt that) {
    if ((x += that.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator-=(ModInt that) {
    if ((x += MOD - that.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator*=(ModInt that) {
    x = (unsigned long long)x * that.x % MOD;
    return *this;
  }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
  ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
  ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
  ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      std::swap(a, b);
      u -= t * v;
      std::swap(u, v);
    }
    return ModInt(u);
  }
  bool operator==(ModInt that) const { return x == that.x; }
  bool operator!=(ModInt that) const { return x != that.x; }
  ModInt operator-() const {
    ModInt t;
    t.x = x == 0 ? 0 : Mod - x;
    return t;
  }
};
template <int MOD>
ostream &operator<<(ostream &st, const ModInt<MOD> a) {
  st << a.get();
  return st;
};
template <int MOD>
ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
  ModInt<MOD> r = 1;
  while (k) {
    if (k & 1) r *= a;
    a *= a;
    k >>= 1;
  }
  return r;
}
int N, M, Q;
string S[505], B[303];
void _main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> S[i];
  cin >> Q;
  for (int i = 0; i < Q; i++) cin >> B[i];
  vector<vector<ModInt<5>>> A(M, vector<ModInt<5>>(N + Q));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) A[j][i] = S[i][j] - 'a';
  for (int i = 0; i < Q; i++)
    for (int j = 0; j < M; j++) A[j][i + N] = B[i][j] - 'a';
  int rank = gaussianElimination(A, N);
  ModInt<1000000007> ans = 1;
  for (int i = 0; i < N - rank; i++) ans *= 5;
  vector<int> zero;
  for (int i = 0; i < M; i++) {
    int ok = 1;
    for (int j = 0; j < N; j++)
      if (A[i][j] == 1) ok = 0;
    if (ok) zero.push_back(i);
  }
  for (int i = 0; i < Q; i++) {
    int ok = 1;
    for (auto &j : zero)
      if (A[j][N + i] != 0) {
        ok = 0;
        break;
      }
    if (ok)
      printf("%d\n", ans.get());
    else
      printf("0\n");
  }
}
