#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
const int M = 25;
const int V = 2e6;
const int E = 2e6;
int eb[V], peb[V], e[E * 2], es[E * 2], ed = 1;
int ef[E * 2], ec[E * 2];
int S, T, v;
int d[V], o[V], r[V];
void init(int v) {
  memset(eb, 0, sizeof(eb[0]) * v);
  ed = 1;
}
void add_e(int v, int u, long long maxflow) {
  ++ed;
  e[ed] = u;
  ef[ed] = 0;
  ec[ed] = maxflow;
  es[ed] = eb[v];
  eb[v] = ed;
  ++ed;
  e[ed] = v;
  ef[ed] = 0;
  ec[ed] = 0;
  es[ed] = eb[u];
  eb[u] = ed;
}
int dfs(int v, int flow) {
  if (!flow || v == T) return flow;
  for (int& k = peb[v]; k; k = es[k]) {
    int u = e[k];
    if (d[v] != d[u] - 1) continue;
    long long push = dfs(u, min(flow, ec[k] - ef[k]));
    if (push) {
      ef[k] += push;
      ef[k ^ 1] -= push;
      return push;
    }
  }
  return 0;
}
bool bfs() {
  memset(d, 0, v * sizeof(d[0]));
  int h = 0, l = 0;
  o[h++] = S;
  d[S] = 1;
  while (l < h) {
    int v = o[l++];
    for (int u, k = eb[v]; k; k = es[k]) {
      u = e[k];
      if (!d[u] && ec[k] > ef[k]) {
        d[u] = d[v] + 1;
        o[h++] = u;
      }
    }
  }
  return d[T];
}
int dinic() {
  int flow = 0, inf = 1e9, pushed;
  while (bfs()) {
    memcpy(peb, eb, v * sizeof(eb[0]));
    do {
      pushed = dfs(S, inf);
      flow += pushed;
    } while (pushed);
  }
  return flow;
}
int dist[M][M][M][M];
char s[M][M];
void ff(int n, int m) {
  for (int X = 1; X <= n; ++X)
    for (int Y = 1; Y <= m; ++Y) {
      vector<pair<int, int>> q;
      dist[X][Y][X][Y] = 0;
      q.push_back({X, Y});
      for (int k = 0; k < q.size(); ++k) {
        int x = q[k].first;
        int y = q[k].second;
        for (int dx = -1; dx < 2; ++dx)
          for (int dy = -1; dy < 2; ++dy)
            if (abs(dx) + abs(dy) == 1) {
              int i = x + dx;
              int j = y + dy;
              if (i < 1 || i > n || j < 1 || j > m || s[i][j] == '#') continue;
              if (dist[X][Y][i][j] > dist[X][Y][x][y] + 1) {
                q.push_back({i, j});
                dist[X][Y][i][j] = dist[X][Y][x][y] + 1;
              }
            }
      }
    }
}
int main() {
  int n, m;
  int c1, c2;
  cin >> n >> m >> c1 >> c2;
  if (abs(c1 - c2) != 1) return cout << -1, 0;
  for (int i = 1; i <= n; ++i) cin >> (s[i] + 1);
  vector<pair<int, int>> p1, p2;
  vector<int> t1, t2;
  int x, y, tm;
  cin >> x >> y >> tm;
  if (c1 + 1 == c2) {
    t1.push_back(tm);
    p1.push_back({x, y});
  } else {
    t2.push_back(tm);
    p2.push_back({x, y});
  }
  for (int i = 0; i < c1; ++i) {
    cin >> x >> y >> tm;
    t1.push_back(tm);
    p1.push_back({x, y});
  }
  for (int i = 0; i < c2; ++i) {
    cin >> x >> y >> tm;
    t2.push_back(tm);
    p2.push_back({x, y});
  }
  memset(dist, 63, sizeof dist);
  ff(n, m);
  c1 = t1.size();
  c2 = t2.size();
  if (c1 > n * m) return cout << -1, 0;
  long long ans = -1;
  long long tl = 0, tr = 1e12;
  while (tl < tr) {
    long long t = (tl + tr) >> 1;
    S = 0;
    T = 1 + c1 + c2 + n * m * 2;
    v = T + 1;
    for (int i = 0; i < c1; ++i) add_e(S, i + 1, 1);
    for (int i = 0; i < c1; ++i) add_e(i + 1 + c1 + n * m * 2, T, 1);
    for (int x = 1; x <= n; ++x)
      for (int y = 1; y <= m; ++y)
        if (s[x][y] == '.') {
          add_e(((x - 1) * m + y - 1) * 2 + 1 + c1,
                ((x - 1) * m + y - 1) * 2 + 1 + 1 + c1, 1);
        }
    for (int x = 1; x <= n; ++x)
      for (int y = 1; y <= m; ++y)
        if (s[x][y] == '.') {
          for (int i = 0; i < c1; ++i) {
            int ax = p1[i].first;
            int ay = p1[i].second;
            if (dist[x][y][ax][ay] > 1e9 ||
                1LL * t1[i] * dist[x][y][ax][ay] > t)
              continue;
            add_e(i + 1, ((x - 1) * m + y - 1) * 2 + 1 + c1, 1);
          }
          for (int j = 0; j < c2; ++j) {
            int bx = p2[j].first;
            int by = p2[j].second;
            if (dist[x][y][bx][by] > 1e9 ||
                1LL * t2[j] * dist[x][y][bx][by] > t)
              continue;
            add_e(((x - 1) * m + y - 1) * 2 + 1 + 1 + c1,
                  j + 1 + c1 + n * m * 2, 1);
          }
        }
    long long f = dinic();
    if (f == c1) {
      tr = t;
      ans = t;
    } else
      tl = t + 1;
    init(v);
  }
  cout << ans << endl;
  return 0;
}
