#include <bits/stdc++.h>
using namespace std;
const int N = 505, M = 1e9 + 7;
vector<vector<int>> gaus;
char c[N];
int n, m, ans = 1, yes[N];
struct lol {
  int t, x, y, m;
  lol(int a = 0, int b = 0, int c = 0, int d = 0) {
    t = a;
    x = b;
    y = c;
    m = d;
  }
};
vector<lol> move1;
int power(int base, int to) {
  int ret = 1;
  while (to) {
    if (to & 1) ret = ret * 1LL * base % M;
    base = base * 1LL * base % M;
    to >>= 1;
  }
  return ret;
}
void add(int &a, int b) {
  a += b;
  if (a >= 5) a -= 5;
  if (a < 0) a += 5;
}
void fix() {
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      int at = 0;
      while (at < n && !gaus[i][at] && !gaus[j][at]) at++;
      if (at == n) break;
      if (gaus[j][at] && !gaus[i][at]) {
        swap(gaus[i], gaus[j]);
        move1.push_back({1, i, j, 0});
        continue;
      }
      if (!gaus[j][at] && gaus[i][at]) continue;
      int x = power((5 - gaus[j][at]) * power(gaus[i][at], 3) % 5, 5) % 5;
      for (int k = 0; k < n; k++) add(gaus[j][k], x * gaus[i][k] % 5);
      move1.push_back({0, i, j, x});
    }
  }
  int freq = 0;
  for (int j = 0; j < m; j++)
    for (int i = 0; i < n; i++)
      if (gaus[j][i]) {
        freq++;
        yes[j] = 1;
        break;
      }
  ans = power(5, max(0, n - freq));
  for (int i = 0; i < m; i++) {
    int at = -1;
    for (int j = 0; j < n; j++)
      if (gaus[i][j]) {
        at = j;
        break;
      }
    if (at == -1) break;
    move1.push_back({0, i, i, power(gaus[i][at], 3)});
  }
}
int main() {
  scanf("%d%d", &n, &m);
  gaus.resize(m);
  for (int i = 0; i < n; i++) {
    scanf(" %s", c);
    for (int j = 0; j < m; j++) gaus[j].push_back(c[j] - 'a');
  }
  fix();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf(" %s", c);
    for (int j = 0; j < m; j++) c[j] -= 'a';
    for (lol j : move1) {
      int x = c[j.y];
      if (j.t == 1)
        swap(c[j.x], c[j.y]);
      else {
        add(x, c[j.x] * j.m % 5);
        c[j.y] = x;
      }
    }
    bool can = 1;
    for (int j = 0; j < m; j++)
      if (c[j] && !yes[j]) can = 0;
    ;
    printf("%d\n", can ? ans : 0);
  }
}
