#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int dst[33][33][33][33];
char grid[33][33];
int cnt[3], t[3][33 * 33];
pair<int, int> p[3][33 * 33];
int V, E, src, tar;
int head[60000], work[60000], dis[60000];
int to[1620000], cap[1620000], nxt[1620000];
int q[60000], qf, qb;
void init(int n, int s, int t) {
  memset(head, -1, sizeof(int) * n);
  V = n;
  E = 0;
  src = s;
  tar = t;
}
void add_edge(int u, int v, int c) {
  to[E] = v;
  cap[E] = c;
  nxt[E] = head[u];
  head[u] = E++;
  to[E] = u;
  cap[E] = 0;
  nxt[E] = head[v];
  head[v] = E++;
}
bool bfs() {
  memset(dis, -1, sizeof(dis));
  qf = qb = 0;
  q[qb++] = src;
  dis[src] = 0;
  while (qf < qb && dis[tar] == -1) {
    int u = q[qf++];
    for (int i = head[u]; i >= 0; i = nxt[i]) {
      int v = to[i];
      if (dis[v] == -1 && cap[i] > 0) {
        dis[v] = dis[u] + 1;
        q[qb++] = v;
      }
    }
  }
  return dis[tar] >= 0;
}
int dfs(int u, int &bot) {
  int v, bot1, delta;
  if (u == tar) return bot;
  for (int &i = work[u]; i >= 0; i = nxt[i]) {
    v = to[i];
    if (dis[v] != dis[u] + 1 || cap[i] == 0) continue;
    bot1 = min(bot, cap[i]);
    if (delta = dfs(v, bot1)) {
      cap[i] -= delta;
      cap[i ^ 1] += delta;
      bot = bot1;
      return delta;
    }
  }
  return 0;
}
int dinic() {
  int ans = 0, delta, bot;
  while (bfs()) {
    memcpy(work, head, sizeof(int) * V);
    delta = 0x3f3f3f3f;
    while (delta = dfs(src, bot = 0x3f3f3f3f)) ans += delta;
  }
  return ans;
}
int can(long long mid, int n, int m) {
  int A = cnt[0], i, j, k, nm = n * m;
  init(A * 2 + 2 * nm + 10, A * 2 + 2 * nm + 1, A * 2 + 2 * nm + 2);
  for (i = 0; i < A; i++) add_edge(src, i, 1);
  for (i = 0; i < A; i++) add_edge(i + A + 2 * nm, tar, 1);
  for (i = 0; i < n * m; i++) add_edge(i + A, i + A + nm, 1);
  for (int ii = 0; ii < 2; ii++)
    for (k = 0; k < A; k++)
      for (i = 0; i < n; i++)
        for (j = 0; j < m; j++) {
          if (grid[i][j] == '#') continue;
          pair<int, int> a = p[ii][k];
          if (dst[a.first][a.second][i][j] < 1000 &&
              (long long)dst[a.first][a.second][i][j] * t[ii][k] <= mid) {
            if (ii)
              add_edge(A + n * m + i * m + j, k + A + 2 * n * m, 1);
            else
              add_edge(k, A + i * m + j, 1);
          }
        }
  return dinic() == A;
}
int main() {
  int i, j, k, ii, jj, iii, jjj, u, v, w, n, m;
  scanf("%d%d%d%d", &n, &m, cnt, cnt + 1);
  for (i = 0; i < n; i++) scanf("%s", grid[i]);
  scanf("%d%d%d", &u, &v, &w);
  u--, v--;
  for (i = 0; i < 2; i++) {
    for (j = 0; j < cnt[i]; j++) {
      scanf("%d%d%d", &p[i][j].first, &p[i][j].second, &t[i][j]);
      p[i][j].first--, p[i][j].second--;
    }
  }
  if (cnt[0] < cnt[1]) {
    p[0][cnt[0]] = pair<int, int>(u, v);
    t[0][cnt[0]++] = w;
  } else {
    p[1][cnt[1]] = pair<int, int>(u, v);
    t[1][cnt[1]++] = w;
  }
  if (cnt[0] != cnt[1]) {
    puts("-1");
    return 0;
  }
  memset(dst, 0x3f, sizeof(dst));
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      if (grid[i][j] == '#') continue;
      dst[i][j][i][j] = 0;
      qf = qb = 0;
      q[qb++] = i, q[qb++] = j;
      while (qf < qb) {
        u = q[qf++], v = q[qf++];
        for (k = 0; k < 4; k++) {
          int uu = u + dx[k], vv = v + dy[k];
          if ((uu < 0 || vv < 0 || uu >= n || vv >= m) || grid[uu][vv] == '#')
            continue;
          if (dst[i][j][uu][vv] > dst[i][j][u][v] + 1) {
            dst[i][j][uu][vv] = dst[i][j][u][v] + 1;
            q[qb++] = uu, q[qb++] = vv;
          }
        }
      }
    }
  long long st = -1, ed = (1LL << 40), mid;
  while (ed - st > 1) {
    mid = (st + ed) / 2;
    if (can(mid, n, m))
      ed = mid;
    else
      st = mid;
  }
  if (ed == (1LL << 40))
    puts("-1");
  else
    printf("%I64d\n", ed);
  return 0;
}
