#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int h[2000050], nxt[2000050], v[2000050], w[2000050], s, tt, dep[200005], ec, m,
    n, a, b;
int x[1000], y[1000], ct, tx[4] = {1, 0, -1, 0}, ty[4] = {0, -1, 0, 1};
long long t[1000], d[1010][1010];
char st[30][30];
void add(int a, int b, int c) {
  v[++ec] = b;
  w[ec] = c;
  nxt[ec] = h[a];
  h[a] = ec;
}
void adj(int a, int b, int c) {
  add(a, b, c);
  add(b, a, 0);
}
bool bfs() {
  queue<int> q;
  q.push(s);
  memset(dep, 0, sizeof(dep));
  dep[s] = 1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = h[x]; i; i = nxt[i])
      if (w[i] > 0 && !dep[v[i]]) dep[v[i]] = dep[x] + 1, q.push(v[i]);
  }
  return dep[tt];
}
int dfs(int x, int dis) {
  if (x == tt || !dis) return dis;
  int tp = 0;
  for (int i = h[x]; i && tp < dis; i = nxt[i])
    if (dep[v[i]] == dep[x] + 1 && w[i] > 0) {
      int f = dfs(v[i], min(dis - tp, w[i]));
      w[i] -= f;
      w[i ^ 1] += f;
      tp += f;
    }
  if (!tp) dep[x] = 0;
  return tp;
}
int din() {
  int aans = 0;
  while (bfs()) aans += dfs(s, 1e9);
  return aans;
}
struct no {
  int x, y;
};
void gd() {
  memset(d, 32, sizeof(d));
  queue<no> q;
  for (int i = 1; i <= a + b; i++) {
    q.push((no){x[i], y[i]});
    d[i][(x[i] - 1) * m + y[i]] = 0;
    while (!q.empty()) {
      no x = q.front();
      q.pop();
      for (int j = 0; j < 4; j++) {
        int nx = x.x + tx[j], ny = x.y + ty[j];
        if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
        int p1 = (nx - 1) * m + ny, p2 = (x.x - 1) * m + x.y;
        if (st[nx][ny] != '#' && d[i][p1] > 1e15) {
          d[i][p1] = d[i][p2] + t[i];
          q.push((no){nx, ny});
        }
      }
    }
  }
}
int pd(long long x) {
  memset(h, 0, sizeof(h));
  ec = 1;
  for (int i = 1; i <= a; i++) adj(s, i, 1);
  for (int i = 1; i <= b; i++) adj(i + a + 2 * n * m, tt, 1);
  for (int i = 1; i <= a; i++)
    for (int j = 1; j <= n * m; j++)
      if (d[i][j] <= x) adj(i, j + a, 1);
  for (int i = 1; i <= b; i++)
    for (int j = 1; j <= n * m; j++)
      if (d[i + a][j] <= x) adj(j + a + n * m, i + a + 2 * n * m, 1);
  for (int i = 1; i <= n * m; i++) adj(i + a, i + a + n * m, 1);
  return din() == a;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  tt = a + b + 2 * n * m + 2;
  if (abs(a - b) != 1) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) scanf("%s", st[i] + 1);
  int xa, ya, ta;
  scanf("%d%d%d", &xa, &ya, &ta);
  for (int i = 1; i <= a; i++) scanf("%d%d%lld", &x[i], &y[i], &t[i]);
  if (a < b) {
    x[++a] = xa;
    y[a] = ya;
    t[a] = ta;
  }
  for (int i = a + 1; i <= a + b; i++) scanf("%d%d%lld", &x[i], &y[i], &t[i]);
  if (a > b) {
    b++;
    x[a + b] = xa;
    y[a + b] = ya;
    t[a + b] = ta;
  }
  gd();
  long long l = 0, r = 1e15, ans = 1e15 + 1;
  while (l <= r) {
    long long md = (l + r) / 2;
    if (pd(md))
      r = md - 1, ans = md;
    else
      l = md + 1;
  }
  if (ans == 1e15 + 1) {
    printf("-1");
    return 0;
  }
  printf("%lld", ans);
}
