#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
double PI = 4 * atan(1);
int n, m, q, bad = 0;
long long po5[501];
int inv[5] = {0, 1, 3, 2, 4};
bool done[500];
vector<int> second[500], s1[500];
string b;
void sub(int num, vector<int>& ori, vector<int>& res) {
  for (int i = 0; i < m; i++) res[i] = ((res[i] - num * ori[i] % 5) + 5) % 5;
}
void gen() {
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      if (!done[j] && second[j][i]) {
        int t = inv[second[j][i]];
        for (int k = i; k < m; k++) second[j][k] = (second[j][k] * t) % 5;
        for (int k = 0; k < n; k++)
          if (!done[k] && k != j) sub(second[k][i], second[j], second[k]);
        done[j] = 1;
        s1[i] = second[j];
        bad--;
        break;
      }
}
void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  po5[0] = 1;
  for (int i = 1; i < 501; i++) {
    po5[i] = (5 * po5[i - 1]) % MOD;
  }
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      second[i].push_back(int(c - 'a'));
    }
  bad = n;
  gen();
  cin >> q;
}
bool ok(string b) {
  vector<int> tmp(m);
  for (int i = 0; i < m; i++) tmp[i] = (b[i] - 'a');
  for (int i = 0; i < m; i++)
    if (tmp[i]) {
      if (s1[i].size() == 0) return 0;
      sub(tmp[i], s1[i], tmp);
    }
  return 1;
}
int main() {
  init();
  for (int i = 0; i < q; i++) {
    cin >> b;
    if (ok(b))
      cout << po5[bad] << "\n";
    else
      cout << 0 << "\n";
  }
}
