#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-10;
const long long MOD = 1e9 + 7;
const long long MOD2 = 5;
const long double PI = 3.1415926535897932384626433832795028841;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
const int maxn = 500 + 5;
const int maxm = 1e5 + 5;
const int maxq = 400 + 5;
int matr_div[5][5] = {{0, 0, 0, 0, 0},
                      {0, 1, 3, 2, 4},
                      {0, 2, 1, 4, 3},
                      {0, 1, 4, 1, 2},
                      {0, 4, 2, 3, 1}};
struct matrix {
  int arr[maxn][maxn + maxq];
  int n, m, q;
  void swap_rows(int r1, int r2) {
    for (int i = 0; i < m + q; i++) {
      swap(arr[r1][i], arr[r2][i]);
    }
  }
  int get_max_val(int col, int from_row) {
    int max_val = 0;
    int ind = -1;
    for (int i = from_row; i < n; i++) {
      if (arr[i][col] > max_val) {
        max_val = arr[i][col];
        ind = i;
      }
    }
    return ind;
  }
  int get_max_row_val(int row) {
    int max_val = 0;
    int ind = -1;
    for (int i = 0; i < m; i++) {
      if (arr[row][i] > max_val) {
        max_val = arr[row][i];
        ind = i;
      }
    }
    return ind;
  }
  void sum_row(int r1, int r2, int mult) {
    for (int i = 0; i < m + q; i++) {
      arr[r1][i] = (arr[r1][i] + arr[r2][i] * mult + MOD2 * 50) % MOD2;
    }
  }
  void show_matrix() {
    cout << "matrix " << n << ',' << m << ":\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m + q; j++) {
        cout << arr[i][j] << ' ';
        if (j == m - 1) {
          cout << "   ";
        }
      }
      cout << '\n';
    }
  }
};
int gauss(matrix *mat) {
  int ans = 0;
  int i = 0;
  int j = 0;
  while (i < mat->n && j < mat->m) {
    int max_ind = mat->get_max_val(j, i);
    if (max_ind == -1) {
      j++;
      continue;
    }
    mat->swap_rows(max_ind, i);
    for (int it_row = 0; it_row < mat->n; it_row++) {
      if (it_row != i) {
        int mult = matr_div[mat->arr[it_row][j]][mat->arr[i][j]];
        mat->sum_row(it_row, i, -mult);
      }
    }
    ans++;
    i++;
    j++;
  }
  return ans;
}
matrix mat;
int main() {
  int n, m;
  cin >> mat.m >> mat.n;
  for (int i = 0; i < mat.m; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      mat.arr[j][i] = s[j] - 'a';
    }
  }
  cin >> mat.q;
  for (int i = 0; i < mat.q; i++) {
    string b;
    cin >> b;
    for (int j = 0; j < b.size(); j++) {
      mat.arr[j][i + mat.m] = b[j] - 'a';
    }
  }
  int ind = gauss(&mat);
  int null_size = mat.m - ind;
  long long comb = powmod(5, null_size);
  int zero_rows[maxn];
  for (int i = 0; i < mat.n; i++) {
    zero_rows[i] = mat.get_max_row_val(i);
  }
  for (int i = 0; i < mat.q; i++) {
    bool bad = 0;
    for (int j = 0; j < mat.n; j++) {
      if (zero_rows[j] == -1 && mat.arr[j][mat.m + i] != 0) {
        bad = 1;
        continue;
      }
    }
    if (bad) {
      cout << 0 << '\n';
    } else {
      cout << comb << '\n';
    }
  }
}
