#include <bits/stdc++.h>
using namespace std;
const int maxn = 502;
const int mod = 1e9 + 7;
int n, m, q, rg = 0, ans, cnti = -1;
int obr[5] = {0, 1, 3, 2, 4};
int arr[maxn][maxn], mas[maxn];
string st;
struct node {
  int type;
  int rw1, rw2;
  int rw, koef;
  node(){};
};
vector<node> posl;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> st;
    for (int j = 0; j < m; ++j) arr[j][i] = st[j] - 'a';
  }
  ans = 1;
  for (int i = 0; i < n; ++i) {
    int j = cnti + 1;
    while (j < m && arr[j][i] == 0) j += 1;
    if (j == m) rg += 1, ans = (5LL * ans) % mod;
    if (j == m) continue;
    cnti += 1;
    if (j > cnti) {
      for (int k = i; k < n; ++k) {
        swap(arr[j][k], arr[cnti][k]);
      }
      posl.push_back(node());
      posl.rbegin()->type = 1;
      posl.rbegin()->rw1 = j;
      posl.rbegin()->rw2 = cnti;
    }
    posl.push_back(node());
    posl.rbegin()->type = 3;
    posl.rbegin()->rw = cnti;
    posl.rbegin()->koef = obr[arr[cnti][i]];
    for (int k = i + 1; k < n; ++k)
      arr[cnti][k] = (arr[cnti][k] * obr[arr[cnti][i]]) % 5;
    arr[cnti][i] = 1;
    for (int j = cnti + 1; j < m; ++j) {
      if (arr[j][i] == 0) continue;
      posl.push_back(node());
      posl.rbegin()->type = 2;
      posl.rbegin()->rw1 = j;
      posl.rbegin()->rw2 = cnti;
      posl.rbegin()->koef = arr[j][i];
      for (int k = i + 1; k < n; ++k)
        arr[j][k] = (arr[j][k] - arr[j][i] * arr[cnti][k] + 25) % 5;
      arr[j][i] = 0;
    }
  }
  cin >> q;
  for (; q > 0; --q) {
    cin >> st;
    for (int i = 0; i < m; ++i) mas[i] = st[i] - 'a';
    for (node d : posl) {
      if (d.type == 1)
        swap(mas[d.rw1], mas[d.rw2]);
      else if (d.type == 2)
        mas[d.rw1] = (mas[d.rw1] - mas[d.rw2] * d.koef + 25) % 5;
      else
        mas[d.rw] = (mas[d.rw] * d.koef) % 5;
    }
    bool bol = true;
    for (int i = cnti + 1; i < m; ++i) {
      if (mas[i] != 0) bol = false;
    }
    if (bol)
      cout << ans << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
