#include <bits/stdc++.h>
int n, m;
std::vector<std::pair<int, int>> swaps;
int GaussA(std::vector<std::vector<int>>& mtrx) {
  int col = 0;
  int line = 1;
  while (col < m && line < n) {
    int pLine = line - 1;
    while (pLine < n && mtrx[pLine][col] == 0) ++pLine;
    if (pLine == n) {
      ++col;
      continue;
    }
    for (int i = 0; i < m; ++i) std::swap(mtrx[line - 1][i], mtrx[pLine][i]);
    if (line - 1 != pLine) swaps.push_back(std::make_pair(line - 1, pLine));
    int pivot = mtrx[line - 1][col];
    for (int i = line; i < n; ++i) {
      int t = 1;
      while ((pivot * t) % 5 != mtrx[i][col]) ++t;
      for (int j = col; j < m; ++j) {
        mtrx[i][j] = ((mtrx[i][j] - (mtrx[line - 1][j] * t) % 5) + 20) % 5;
      }
    }
    ++col;
    ++line;
  }
  int rk = 0;
  line = 0;
  while (line < n) {
    col = 0;
    while (col < m && mtrx[line][col] == 0) ++col;
    if (col != m) {
      ++rk;
    }
    ++line;
  }
  return rk;
}
bool GaussB(int rank, const std::vector<std::vector<int>>& mtrx,
            std::vector<int> nextV) {
  int col = 0;
  for (int i = 0; i < rank; ++i) {
    while (mtrx[i][col] == 0) ++col;
    int t = 1;
    while ((mtrx[i][col] * t) % 5 != nextV[col]) ++t;
    for (int j = col; j < m; ++j) {
      nextV[j] = ((nextV[j] - (mtrx[i][j] * t) % 5) + 20) % 5;
    }
  }
  for (int j = 0; j < m; ++j) {
    if (nextV[j] != 0) return false;
  }
  return true;
}
int main() {
  std::cin >> n >> m;
  std::vector<std::vector<int>> mtrx(n, std::vector<int>(m));
  for (int i = 0; i < n; ++i) {
    std::string s;
    std::cin >> s;
    for (int j = 0; j < m; ++j) {
      mtrx[i][j] = s[j] - 'a';
    }
  }
  int rk = GaussA(mtrx);
  long long five = 1;
  for (int i = 0; i < n - rk; ++i) {
    five = (five * 5) % 1000000007;
  }
  int q;
  std::cin >> q;
  for (int i = 0; i < q; ++i) {
    std::string s;
    std::cin >> s;
    std::vector<int> word(m);
    for (int j = 0; j < m; ++j) {
      word[j] = s[j] - 'a';
    }
    if (GaussB(rk, mtrx, word)) {
      std::cout << five << "\n";
    } else {
      std::cout << "0\n";
    }
  }
}
