#include <bits/stdc++.h>
using namespace std;
const int MAXV = 2000;
const int MAXE = 500000;
const int INF = (int)1e7 + 10;
struct E {
  int to, co;
  E(int t = 0, int c = 0) : to(t), co(c) {}
} eg[2 * MAXE];
struct Flow {
  vector<int> e[MAXV];
  int ei, v;
  void init(int n) {
    v = n;
    ei = 0;
    for (int i = 0; i < n; i++) e[i] = vector<int>();
  }
  void add(int a, int b, int c) {
    eg[ei] = E(b, c);
    e[a].push_back(ei);
    ei++;
    eg[ei] = E(a, 0);
    e[b].push_back(ei);
    ei++;
  }
  int d[MAXV], qu[MAXV], ql, qr;
  bool BFS() {
    memset(d, -1, v * sizeof(int));
    ql = qr = 0;
    qu[qr++] = 0;
    d[0] = 0;
    while (ql < qr && d[v - 1] == -1) {
      int n = qu[ql++];
      vector<int> &v = e[n];
      for (int i = v.size() - 1; i >= 0; i--) {
        int u = v[i];
        if (d[eg[u].to] == -1 && eg[u].co > 0) {
          d[eg[u].to] = d[n] + 1;
          qu[qr++] = eg[u].to;
        }
      }
    }
    return d[v - 1] != -1;
  }
  int ptr[MAXV];
  int go(int n, int p) {
    if (n == v - 1) return p;
    vector<int> &u = e[n];
    int temp;
    for (int i = ptr[n]; i < ((int)(u).size()); i++) {
      if (d[n] + 1 != d[eg[u[i]].to] || eg[u[i]].co == 0) continue;
      if ((temp = go(eg[u[i]].to, min(p, eg[u[i]].co))) == 0) continue;
      eg[u[i]].co -= temp;
      eg[u[i] ^ 1].co += temp;
      ptr[n] = i;
      return temp;
    }
    ptr[n] = ((int)(u).size());
    return 0;
  }
  int max_flow() {
    int ans = 0, temp;
    while (BFS()) {
      for (int i = 0; i < v; i++) ptr[i] = 0;
      while ((temp = go(0, INF)) > 0) ans += temp;
    }
    return ans;
  }
} flow;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
char s[25][25];
int num[25][25];
int d[25][25];
vector<pair<pair<int, int>, int> > man, wom;
int n, m, space;
bool check(long long c) {
  int sink = 1 + ((int)(man).size()) + space + space + ((int)(wom).size());
  flow.init(sink + 1);
  for (int i = 0; i < ((int)(man).size()); i++) {
    memset(d, -1, sizeof(d));
    queue<pair<int, int> > que;
    d[man[i].first.first][man[i].first.second] = 0;
    que.push(man[i].first);
    while (!que.empty()) {
      pair<int, int> t = que.front();
      que.pop();
      int nd = d[t.first][t.second] + 1;
      flow.add(
          i + 1,
          num[t.first][t.second] + ((int)(man).size()) + ((int)(man).size()),
          1);
      for (int j = 0; j < 4; j++) {
        int nx = t.first + dx[j], ny = t.second + dy[j];
        if (num[nx][ny] && d[nx][ny] == -1 && 1ll * nd * man[i].second <= c) {
          d[nx][ny] = nd;
          que.push(make_pair(nx, ny));
        }
      }
    }
  }
  for (int i = 0; i < ((int)(wom).size()); i++) {
    memset(d, -1, sizeof(d));
    queue<pair<int, int> > que;
    d[wom[i].first.first][wom[i].first.second] = 0;
    que.push(wom[i].first);
    while (!que.empty()) {
      pair<int, int> t = que.front();
      que.pop();
      int nd = d[t.first][t.second] + 1;
      flow.add(((int)(man).size()) + ((int)(man).size()) + space +
                   num[t.first][t.second],
               ((int)(man).size()) + i + 1, 1);
      for (int j = 0; j < 4; j++) {
        int nx = t.first + dx[j], ny = t.second + dy[j];
        if (num[nx][ny] && d[nx][ny] == -1 && 1ll * nd * wom[i].second <= c) {
          d[nx][ny] = nd;
          que.push(make_pair(nx, ny));
        }
      }
    }
  }
  for (int i = 1; i <= ((int)(man).size()); i++)
    flow.add(0, i, 1), flow.add(((int)(man).size()) + i, sink, 1);
  for (int i = 1; i <= space; i++)
    flow.add(((int)(man).size()) + ((int)(man).size()) + i,
             ((int)(man).size()) + ((int)(man).size()) + space + i, 1);
  return flow.max_flow() >= ((int)(man).size());
}
int main() {
  int boy, girl, r, c, t, max_t = -1;
  scanf("%d%d%d%d", &n, &m, &boy, &girl);
  if (!(boy == girl - 1 || girl == boy - 1)) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] == '.') num[i][j] = ++space;
  if (space < max(boy, girl)) {
    puts("-1");
    return 0;
  }
  scanf("%d%d%d", &r, &c, &t);
  max_t = max(max_t, t);
  if (boy == girl - 1)
    man.push_back(make_pair(make_pair(r, c), t));
  else
    wom.push_back(make_pair(make_pair(r, c), t));
  for (int i = 0; i < boy; i++) {
    scanf("%d%d%d", &r, &c, &t);
    max_t = max(max_t, t);
    man.push_back(make_pair(make_pair(r, c), t));
  }
  for (int i = 0; i < girl; i++) {
    scanf("%d%d%d", &r, &c, &t);
    max_t = max(max_t, t);
    wom.push_back(make_pair(make_pair(r, c), t));
  }
  assert(((int)(man).size()) == ((int)(wom).size()));
  long long L = 0, R = 1ll * max_t * n * m, M;
  while (L <= R) {
    M = (L + R) / 2;
    if (check(M))
      R = M - 1;
    else
      L = M + 1;
  }
  if (L > 1ll * max_t * n * m)
    puts("-1");
  else
    printf("%I64d\n", L);
  return 0;
}
