#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 11 + 4;
const long long MAXE = 2e5;
const long long MAX = 1000;
const long long INF = 1e18 + 1000;
long long n, m, x, y, ec;
char c[MAXN][MAXN];
long long dis[MAX][MAX];
long long from[2 * MAXE], to[2 * MAXE], cap[2 * MAXE], prv[2 * MAXE];
long long head[MAX];
bool mark[MAX];
vector<pair<long long, long long>> vec, sec;
bool fit(long long a, long long b) {
  return a >= 0 && a < n && b >= 0 && b < m;
}
long long hhash(long long a, long long b) { return a * m + b; }
void init() {
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++)
      for (long long w = 0; w < n; w++)
        for (long long o = 0; o < m; o++)
          if (i != w || j != o) dis[hhash(i, j)][hhash(w, o)] = INF;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      if (c[i][j] == '#') continue;
      long long h = hhash(i, j);
      if (fit(i + 1, j) && c[i + 1][j] != '#') dis[h][hhash(i + 1, j)] = 1;
      if (fit(i - 1, j) && c[i - 1][j] != '#') dis[h][hhash(i - 1, j)] = 1;
      if (fit(i, j + 1) && c[i][j + 1] != '#') dis[h][hhash(i, j + 1)] = 1;
      if (fit(i, j - 1) && c[i][j - 1] != '#') dis[h][hhash(i, j - 1)] = 1;
    }
  for (long long k = 0; k < n * m; k++)
    for (long long i = 0; i < n * m; i++)
      for (long long j = 0; j < n * m; j++)
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
void put_edge(long long u, long long v, long long uv, long long vu = 0) {
  from[ec] = u, to[ec] = v, cap[ec] = uv, prv[ec] = head[u];
  head[u] = ec++;
  from[ec] = v, to[ec] = u, cap[ec] = vu, prv[ec] = head[v];
  head[v] = ec++;
}
void put(long long maxi) {
  memset(head, -1, sizeof(head));
  ec = 0;
  long long source = x + y + 2 * n * m;
  long long sink = source + 1;
  for (long long i = 0; i < x; i++) put_edge(source, i, 1);
  for (long long i = 0; i < x; i++) {
    long long h = vec[i].first, v = vec[i].second;
    for (long long j = 0; j < n; j++)
      for (long long w = 0; w < m; w++) {
        long long hh = hhash(j, w);
        if (dis[h][hh] == INF) continue;
        long long time = v * dis[h][hh];
        if (time > maxi) continue;
        put_edge(i, hh + x, 1);
      }
  }
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      long long hh = hhash(i, j);
      hh += x;
      put_edge(hh, hh + n * m, 1);
    }
  for (long long i = 0; i < y; i++) {
    long long id = x + 2 * n * m + i;
    long long h = sec[i].first, v = sec[i].second;
    for (long long j = 0; j < n; j++)
      for (long long w = 0; w < m; w++) {
        long long hh = hhash(j, w);
        if (dis[h][hh] == INF) continue;
        long long temp = v * dis[h][hh];
        if (temp > maxi) continue;
        put_edge(x + hh + n * m, id, 1);
      }
  }
  for (long long i = 0; i < y; i++) {
    long long id = x + 2 * n * m + i;
    put_edge(id, sink, 1);
  }
}
long long dfs(long long v, long long sink, long long mini = INF) {
  if (sink == v) return mini;
  if (mark[v]) return 0;
  mark[v] = 1;
  for (long long e = head[v]; e != -1; e = prv[e])
    if (cap[e]) {
      long long xx = dfs(to[e], sink, min(mini, cap[e]));
      if (xx == 0) continue;
      cap[e] -= xx;
      cap[e ^ 1] += xx;
      return xx;
    }
  return 0;
}
long long max_flow(long long source, long long sink) {
  memset(mark, 0, sizeof(mark));
  long long ret = 0, xx;
  while ((xx = dfs(source, sink))) {
    ret += xx;
    memset(mark, 0, sizeof(mark));
  }
  return ret;
}
int main() {
  cin >> n >> m >> x >> y;
  if ((x + y + 1) % 2) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> c[i][j];
  init();
  {
    long long a, b, v;
    cin >> a >> b >> v;
    a--, b--;
    if (x < y) {
      x++;
      vec.push_back({hhash(a, b), v});
    } else
      sec.push_back({hhash(a, b), v}), y++;
    long long i = 0;
    if (vec.size()) i++;
    for (; i < x; i++) {
      cin >> a >> b >> v;
      a--, b--;
      vec.push_back({hhash(a, b), v});
    }
    i = 0;
    if (sec.size()) i++;
    for (; i < y; i++) {
      cin >> a >> b >> v;
      a--, b--;
      sec.push_back({hhash(a, b), v});
    }
  }
  long long b = 0, e = 1e18, mid, ret = -1;
  while (b <= e) {
    mid = (b + e) / 2;
    put(mid);
    if (max_flow(x + y + 2 * n * m, x + y + 2 * n * m + 1) == x) {
      e = mid - 1;
      ret = mid;
    } else
      b = mid + 1;
  }
  cout << ret << endl;
  return 0;
}
