#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main(int argc, char *argv[]) {
  cin.sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      a[i][j] = s[j] - 'a';
    }
  }
  vector<vector<int>> b(m, vector<int>(m));
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j]) {
        if (!b[j][j]) {
          b[j] = a[i];
          cnt++;
          break;
        }
        int p;
        for (p = 0; p < 5; p++) {
          if (b[j][j] * p % 5 == a[i][j]) {
            break;
          }
        }
        for (int k = j; k < m; k++) {
          a[i][k] = (a[i][k] - b[j][k] * p % 5 + 5) % 5;
        }
      }
    }
  }
  vector<long long> P5(1005);
  P5[0] = 1;
  for (int i = 1; i <= 1000; i++) {
    P5[i] = P5[i - 1] * 5 % mod;
  }
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    vector<int> vec(m);
    for (int i = 0; i < m; i++) {
      vec[i] = s[i] - 'a';
    }
    bool flag = true;
    for (int i = 0; i < m; i++) {
      if (vec[i]) {
        if (!b[i][i]) {
          flag = false;
          break;
        }
      }
      int p;
      for (p = 0; p < 5; p++) {
        if (b[i][i] * p % 5 == vec[i]) {
          break;
        }
      }
      for (int k = i; k < m; k++) {
        vec[k] = (vec[k] - b[i][k] * p % 5 + 5) % 5;
      }
    }
    if (flag) {
      cout << P5[n - cnt] << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}
