#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, p1, p2, ay[25 * 25], ax[25 * 25], ac[25 * 25], by[25 * 25],
    bx[25 * 25], bc[25 * 25], dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};
int f[2000], v[1000000], o[1000000], w[1000000], p, d[2000], q[2000], fl, S, T;
long long dis[25 * 25][25 * 25];
char s[25][25];
void bd(int a, int b) {
  v[++p] = b;
  o[p] = f[a];
  f[a] = p;
  w[p] = 1;
  v[++p] = a;
  o[p] = f[b];
  f[b] = p;
  w[p] = 0;
}
int dfs(int y, int ff) {
  if (y == T) {
    fl += ff;
    return ff;
  }
  int cap = ff;
  for (int i = (f[y]); i; i = o[i])
    if (w[i] && d[v[i]] == d[y] + 1) {
      int x = dfs(v[i], min(cap, w[i]));
      cap -= x;
      w[i] -= x;
      w[i ^ 1] += x;
      if (!cap) break;
    }
  if (cap == ff) d[y] = -1;
  return ff - cap;
}
bool bfs() {
  for (int i = (0); i <= (T); i++) d[i] = -1;
  d[S] = 0;
  int l = 0, h = 0;
  q[h++] = S;
  while (l < h) {
    int y = q[l++];
    for (int i = (f[y]); i; i = o[i])
      if (w[i] && d[v[i]] < 0) {
        d[v[i]] = d[y] + 1;
        q[h++] = v[i];
        if (v[i] == T) return 1;
      }
  }
  return 0;
}
bool ok(long long val) {
  p = 1;
  for (int i = (0); i <= (T); i++) f[i] = 0;
  for (int i = (0); i < (a); i++) bd(S, i);
  for (int i = (0); i < (b); i++) bd(a + i, T);
  for (int i = (0); i < (n * m); i++) {
    bd(a + b + i, a + b + i + n * m);
    for (int j = (0); j < (a); j++)
      if (dis[(ay[j] - 1) * m + ax[j] - 1][i] <= val / ac[j]) bd(j, a + b + i);
    for (int j = (0); j < (b); j++)
      if (dis[(by[j] - 1) * m + bx[j] - 1][i] <= val / bc[j])
        bd(a + b + i + n * m, a + j);
  }
  fl = 0;
  while (bfs())
    while (dfs(S, a))
      ;
  return fl == a;
}
int main() {
  scanf("%d %d %d %d", &n, &m, &a, &b);
  if (abs(a - b) != 1) {
    puts("-1");
    return 0;
  }
  for (int i = (0); i < (n * m); i++)
    for (int j = (0); j < (n * m); j++) dis[i][j] = 1000000000000LL;
  for (int i = (0); i < (n); i++) scanf("%s", s[i]);
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (m); j++) {
      if (s[i][j] == '#') continue;
      int e = i * m + j;
      dis[e][e] = 0;
      for (int k = (0); k < (4); k++) {
        int ni = i + dy[k], nj = j + dx[k], ne = ni * m + nj;
        if (ni < 0 || ni >= n || nj < 0 || nj >= m || s[ni][nj] == '#')
          continue;
        dis[e][ne] = 1;
      }
    }
  for (int k = (0); k < (n * m); k++)
    for (int i = (0); i < (n * m); i++)
      for (int j = (0); j < (n * m); j++)
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
  if (a > b) {
    scanf("%d %d %d", &by[0], &bx[0], &bc[0]);
    p2++;
  } else {
    scanf("%d %d %d", &ay[0], &ax[0], &ac[0]);
    p1++;
  }
  for (int i = (0); i < (a); i++) {
    scanf("%d %d %d", &ay[p1], &ax[p1], &ac[p1]);
    p1++;
  }
  for (int i = (0); i < (b); i++) {
    scanf("%d %d %d", &by[p2], &bx[p2], &bc[p2]);
    p2++;
  }
  a = b = max(a, b);
  S = a + b + n * m + n * m;
  T = S + 1;
  long long l = 0, h = 1000000000000LL;
  while (l < h) {
    long long m = l + h >> 1;
    if (ok(m))
      h = m;
    else
      l = m + 1;
  }
  if (h == 1000000000000LL)
    puts("-1");
  else
    printf("%I64d\n", h);
}
