#include <bits/stdc++.h>
using namespace std;
int storage[10][10];
long long pwr(long long base, long long p, long long mod) {
  if (mod == 5) {
    p %= 4;
    if (storage[base][p] != -1) return storage[base][p];
  }
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  if (mod == 5) return storage[base][p] = ans;
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n, m, q, powers[6][6];
char str[505][505], pat[505];
int multiply(int a, int b) {
  if (a > b) swap(a, b);
  if (a == 0) return 0;
  if (a == 1) return b;
  if (a == 2) {
    if (b == 2) return 4;
    if (b == 3) return 1;
    if (b == 4) return 3;
  }
  if (a == 3) {
    if (b == 3) return 4;
    if (b == 4) return 2;
  }
  if (a == 4) return 1;
  assert(0);
  return 0;
}
int mod = 5, where[1002], arr[1002][1002];
void gaussian_elimination() {
  memset(where, -1, sizeof(where));
  for (int col = 0, row = 0; col < n && row < m; col++) {
    int sel = row;
    for (int i = row; i < m; i++)
      if (arr[i][col] > arr[sel][col]) sel = i;
    if (arr[sel][col] == 0) continue;
    for (int j = col; j < n + q; j++) swap(arr[sel][j], arr[row][j]);
    where[col] = row;
    for (int i = 0; i < m; i++) {
      if (i == row) continue;
      int mul = multiply(arr[i][col], pwr(arr[row][col], mod - 2, mod));
      for (int j = col; j < n + q; j++) {
        arr[i][j] -= multiply(mul, arr[row][j]);
        while (arr[i][j] < 0) arr[i][j] += mod;
        while (arr[i][j] >= mod) arr[i][j] -= mod;
      }
    }
    row++;
  }
}
int ans[1002];
long long solutions = -1;
long long solve(int q) {
  for (int i = 0; i < n; i++)
    if (where[i] != -1)
      ans[i] =
          multiply(arr[where[i]][n + q], pwr(arr[where[i]][i], mod - 2, mod));
    else
      ans[i] = 0;
  for (int i = 0; i < m; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += multiply(ans[j], arr[i][j]);
      while (sum < 0) sum += mod;
      while (sum >= mod) sum -= mod;
    }
    if (sum != arr[i][n + q]) return 0;
  }
  int unused = 0;
  for (int i = 0; i < n; i++)
    if (where[i] == -1) unused++;
  if (solutions == -1) solutions = pwr(mod, unused, (1000000007LL));
  return solutions;
}
int main() {
  memset(storage, -1, sizeof(storage));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", str[i]);
  }
  scanf("%d", &q);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) arr[i][j] = str[j][i] - 'a';
  for (int j = 0; j < q; j++) {
    scanf("%s", pat);
    for (int i = 0; i < m; i++) arr[i][n + j] = pat[i] - 'a';
  }
  gaussian_elimination();
  for (int j = 0; j < q; j++) {
    printf("%lld\n", solve(j));
  }
  return 0;
}
