#include <bits/stdc++.h>
using namespace std;
int inv[5], n, m, q, mat[500][800];
vector<int> vemat;
bool cek_bisa(int y) {
  int i, x;
  for (i = 0; i <= (int)vemat.size() - 1; i++) {
    x = vemat[i];
    if (mat[x][y]) {
      return false;
    }
  }
  return true;
}
bool isnol(int x) {
  int y;
  for (y = 0; y <= n - 1; y++) {
    if (mat[x][y]) {
      return false;
    }
  }
  return true;
}
void tuker_baris(int x1, int x2) {
  int y;
  for (y = 0; y <= n + q - 1; y++) {
    swap(mat[x1][y], mat[x2][y]);
  }
}
void cetak() {
  return;
  cout << "\n";
  int i, j;
  for (i = 0; i <= m - 1; i++) {
    for (j = 0; j <= n + q - 1; j++) {
      cout << mat[i][j] << " ";
    }
    cout << "\n";
  }
  cout << "\n";
}
int solve() {
  int ret = 0, i, i2, j, rasio, kur;
  for (i = 0; i <= min(m, n) - 1; i++) {
    if (!mat[i][i]) {
      for (i2 = i + 1; i2 <= m - 1; i2++) {
        if (mat[i2][i]) {
          cetak();
          tuker_baris(i2, i);
          break;
        }
      }
      if (i2 == m) {
        continue;
      }
    }
    for (i2 = 0; i2 <= m - 1; i2++) {
      if (i2 == i) {
        continue;
      }
      rasio = (mat[i2][i] * inv[mat[i][i]]) % 5;
      for (j = 0; j <= n + q - 1; j++) {
        kur = (rasio * mat[i][j]) % 5;
        mat[i2][j] -= kur;
        if (mat[i2][j] < 0) mat[i2][j] += 5;
      }
    }
    cetak();
  }
  for (i = 0; i <= m - 1; i++) {
    if (!isnol(i)) {
      ret++;
    } else {
      vemat.push_back(i);
    }
  }
  return ret;
}
int main() {
  int i, j, has, rank, sim, mod = 1000000007;
  char kar;
  inv[1] = 1;
  inv[2] = 3;
  inv[3] = 2;
  inv[4] = 4;
  cin >> n >> m;
  for (j = 0; j <= n - 1; j++) {
    for (i = 0; i <= m - 1; i++) {
      cin >> kar;
      mat[i][j] = kar - 'a';
    }
  }
  cin >> q;
  for (j = n; j <= n + q - 1; j++) {
    for (i = 0; i <= m - 1; i++) {
      cin >> kar;
      mat[i][j] = kar - 'a';
    }
  }
  cetak();
  rank = solve();
  has = 1;
  for (i = 1; i <= n - rank; i++) {
    sim = has;
    has <<= 1;
    has %= mod;
    has <<= 1;
    has %= mod;
    has += sim;
    has %= mod;
  }
  cetak();
  for (j = n; j <= n + q - 1; j++) {
    if (cek_bisa(j)) {
      cout << has << "\n";
    } else {
      cout << "0\n";
    }
  }
}
