#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int MAXN = 24;
const int MAXA = 514;
const int INF = 1029384756;
class Isap {
 public:
  static const int MXN = MAXA * 4;
  class Edge {
   public:
    int v, f, re;
    Edge() { v = f = re = -1; }
    Edge(int _v, int _f, int _r) {
      v = _v;
      f = _f;
      re = _r;
    }
  };
  int n, s, t, h[MXN], gap[MXN];
  vector<Edge> E[MXN];
  void init(int _n, int _s, int _t) {
    n = _n;
    s = _s;
    t = _t;
    for (int i = 0; i < n; i++) E[i].clear();
  }
  void add_edge(int u, int v, int f) {
    E[u].push_back(Edge(v, f, E[v].size()));
    E[v].push_back(Edge(u, 0, E[u].size() - 1));
  }
  int DFS(int u, int nf, int res = 0) {
    if (u == t) return nf;
    for (auto &it : E[u]) {
      if (h[u] == h[it.v] + 1 && it.f > 0) {
        int tf = DFS(it.v, min(nf, it.f));
        res += tf;
        nf -= tf;
        it.f -= tf;
        E[it.v][it.re].f += tf;
        if (nf == 0) return res;
      }
    }
    if (nf) {
      if (--gap[h[u]] == 0) h[s] = n;
      gap[++h[u]]++;
    }
    return res;
  }
  int flow(int res = 0) {
    memset((h), 0, sizeof(h));
    memset((gap), 0, sizeof(gap));
    gap[0] = n;
    while (h[s] < n) res += DFS(s, 2147483647);
    return res;
  }
} flow;
int N, M, L;
bool arr[MAXN][MAXN];
int r[MAXA * 2], c[MAXA * 2];
long long t[MAXA * 2];
int no[MAXN][MAXN];
int dis[MAXA][MAXA];
vector<int> edge[MAXA];
void dijk() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (!arr[i][j]) continue;
      for (int k = 0; k < 4; k++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (nx >= 0 && nx < N && ny >= 0 && ny < M && arr[nx][ny])
          edge[no[i][j]].push_back(no[nx][ny]);
      }
    }
  }
  for (int i = 0; i < N * M; i++)
    for (int j = 0; j < N * M; j++) dis[i][j] = INF;
  for (int i = 0; i < N * M; i++) dis[i][i] = 0;
  for (int i = 0; i < N * M; i++) {
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto u : edge[v]) {
        if (dis[i][u] == INF) {
          dis[i][u] = dis[i][v] + 1;
          q.push(u);
        }
      }
    }
  }
}
bool test(long long m) {
  int n = 2 * L + 2 * N * M + 2;
  int ss = n - 2, tt = n - 1;
  flow.init(n, ss, tt);
  for (int i = 0; i < 2 * L; i++) {
    int x = r[i], y = c[i];
    int v = no[x][y];
    if (i < L)
      flow.add_edge(ss, i, 1);
    else
      flow.add_edge(i, tt, 1);
    for (int u = 0; u < N * M; u++) {
      if (dis[v][u] == INF || t[i] * dis[v][u] > m) continue;
      if (i < L)
        flow.add_edge(i, 2 * L + u, 1);
      else
        flow.add_edge(2 * L + N * M + u, i, 1);
    }
  }
  for (int i = 0; i < N * M; i++)
    flow.add_edge(2 * L + i, 2 * L + N * M + i, 1);
  int res = flow.flow();
  return res == L;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int male, female;
  cin >> N >> M >> male >> female;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < M; j++) arr[i][j] = (s[j] == '.');
  }
  L = max(male, female);
  if (male == female - 1)
    cin >> r[L - 1] >> c[L - 1] >> t[L - 1];
  else if (male == female + 1)
    cin >> r[2 * L - 1] >> c[2 * L - 1] >> t[2 * L - 1];
  else {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < male; i++) cin >> r[i] >> c[i] >> t[i];
  for (int i = 0; i < female; i++) cin >> r[L + i] >> c[L + i] >> t[L + i];
  for (int i = 0; i < 2 * L; i++) {
    r[i]--;
    c[i]--;
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) no[i][j] = i * M + j;
  dijk();
  long long mx = 1E12;
  long long lb = 0, rb = mx;
  while (lb < rb) {
    long long mb = (lb + rb) / 2;
    if (test(mb))
      rb = mb;
    else
      lb = mb + 1;
  }
  long long ans = lb;
  if (ans == mx) ans = -1;
  cout << ans << endl;
  return 0;
}
