#include <bits/stdc++.h>
using namespace std;
const int N = 25;
const int dirU[] = {0, 1, 0, -1};
const int dirV[] = {-1, 0, 1, 0};
int n, m, male, female;
int x[2][N * N], y[2][N * N], t[2][N * N], cnt[2];
char a[N][N];
long long h[2][N * N][N][N];
int used[N][N], cntUsed;
pair<int, int> q[N * N];
int top;
void bfs(int uu, int vv, int id, int r) {
  top = 1;
  cntUsed++;
  used[uu][vv] = cntUsed;
  q[0] = make_pair(uu, vv);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      h[id][r][i][j] = (1ll << 60);
    }
  }
  h[id][r][uu][vv] = 0;
  for (int i = 0; i < top; i++) {
    int u = q[i].first;
    int v = q[i].second;
    for (int j = 0; j < 4; j++) {
      int nu = u + dirU[j];
      int nv = v + dirV[j];
      if (nu < 1 || nu > n || nv < 1 || nv > m) {
        continue;
      }
      if (a[nu][nv] == '#' || used[nu][nv] >= cntUsed) {
        continue;
      }
      used[nu][nv] = cntUsed;
      h[id][r][nu][nv] = h[id][r][u][v] + t[id][r];
      q[top++] = make_pair(nu, nv);
    }
  }
}
int getId(int u, int v) { return m * (u - 1) + v + cnt[0] + cnt[1]; }
int getId1(int u, int v) { return getId(u, v) + n * m; }
const int V = 1e6;
struct Flow {
  int n, s, t, cnt, top;
  int head[V], to[V], nxt[V], c[V], f[V], q[V], h[V], cur[V];
  Flow(int n, int s, int t) {
    this->n = n;
    this->s = s;
    this->t = t;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      head[i] = -1;
    }
  }
  void addEdge(int u, int v, int _c) {
    to[cnt] = v, c[cnt] = _c, f[cnt] = 0, nxt[cnt] = head[u], head[u] = cnt++;
    to[cnt] = u, c[cnt] = 0, f[cnt] = 0, nxt[cnt] = head[v], head[v] = cnt++;
  }
  bool bfs() {
    top = 1;
    q[0] = s;
    for (int i = 0; i < n; i++) {
      h[i] = -1;
    }
    h[s] = 0;
    for (int i = 0; i < top; i++) {
      int u = q[i];
      for (int id = head[u]; id != -1; id = nxt[id]) {
        int v = to[id];
        if (h[v] < 0 && c[id] > f[id]) {
          h[v] = h[u] + 1;
          q[top++] = v;
        }
      }
    }
    return h[t] > 0;
  }
  int dfs(int u, int now) {
    if (u == t) {
      return now;
    }
    for (int &id = cur[u]; id != -1; id = nxt[id]) {
      int v = to[id];
      if (h[v] == h[u] + 1 && c[id] > f[id]) {
        int foo = dfs(v, min(now, c[id] - f[id]));
        if (foo) {
          f[id] += foo;
          f[id ^ 1] -= foo;
          return foo;
        }
      }
    }
    return 0;
  }
  int maxFlow() {
    int res = 0;
    while (bfs()) {
      for (int i = 0; i < n; i++) {
        cur[i] = head[i];
      }
      while (1) {
        int f = dfs(s, 2e9);
        if (!f) {
          break;
        }
        res += f;
      }
    }
    return res;
  }
};
bool check(long long lim) {
  Flow f(getId1(n, m) + 2, 0, getId1(n, m) + 1);
  for (int i = 1; i <= cnt[0]; i++) {
    f.addEdge(f.s, i, 1);
    f.addEdge(i + cnt[0], f.t, 1);
  }
  for (int id = 1; id <= cnt[0]; id++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (h[0][id][i][j] <= lim) {
          f.addEdge(id, getId(i, j), 1);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      f.addEdge(getId(i, j), getId1(i, j), 1);
    }
  }
  for (int id = 1; id <= cnt[1]; id++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (h[1][id][i][j] <= lim) {
          f.addEdge(getId1(i, j), id + cnt[0], 1);
        }
      }
    }
  }
  return f.maxFlow() >= cnt[0];
}
int main() {
  scanf("%d %d %d %d", &n, &m, &male, &female);
  if (abs(male - female) != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i] + 1);
  }
  if (male > female) {
    cnt[1]++;
    scanf("%d %d %d", x[1] + cnt[1], y[1] + cnt[1], t[1] + cnt[1]);
  } else {
    cnt[0]++;
    scanf("%d %d %d", x[0] + cnt[0], y[0] + cnt[0], t[0] + cnt[0]);
  }
  for (int i = 1; i <= male; i++) {
    cnt[0]++;
    scanf("%d %d %d", x[0] + cnt[0], y[0] + cnt[0], t[0] + cnt[0]);
  }
  for (int i = 1; i <= female; i++) {
    cnt[1]++;
    scanf("%d %d %d", x[1] + cnt[1], y[1] + cnt[1], t[1] + cnt[1]);
  }
  for (int i = 1; i <= cnt[0]; i++) {
    bfs(x[0][i], y[0][i], 0, i);
  }
  for (int i = 1; i <= cnt[1]; i++) {
    bfs(x[1][i], y[1][i], 1, i);
  }
  long long low = -1, high = 1e13;
  while (high - low > 1) {
    long long mid = (high + low) >> 1ll;
    if (check(mid)) {
      high = mid;
    } else {
      low = mid;
    }
  }
  printf("%I64d", high >= 1e13 ? -1ll : high);
  return 0;
}
