#include <bits/stdc++.h>
using namespace std;
char str[2010][2010];
int pla1[2010][2], spe1[2010], pla2[2010][2], spe2[2010], r, c,
    dist[2010][2010];
int head[2010], cur[2010], nxt[2010 * 2010], to[2010 * 2010], val[2010 * 2010],
    idx = 1, cnt, n, m, s, t, many, sum, dis[2010];
long long L, R;
void add(int a, int b, int c) {
  nxt[++idx] = head[a], to[idx] = b, val[idx] = c, head[a] = idx;
}
bool bfs() {
  queue<int> q;
  memset(dis, -1, sizeof dis), dis[s] = 0, q.push(s);
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (int i = head[p]; i; i = nxt[i])
      if (dis[to[i]] == -1 && val[i]) dis[to[i]] = dis[p] + 1, q.push(to[i]);
  }
  return dis[t] != -1;
}
int dfs(int p, int flow) {
  if (p == t) return flow;
  int now, temp = flow;
  for (int i = cur[p]; i; i = nxt[i])
    if (dis[to[i]] == dis[p] + 1 && val[i]) {
      now = dfs(to[i], min(temp, val[i]));
      if (!now) dis[to[i]] = -1;
      val[i] -= now, temp -= now, val[i ^ 1] += now;
      if (val[i]) cur[p] = i;
      if (!temp) break;
    }
  return flow - temp;
}
bool check(long long x) {
  s = n + m + r * c * 2 + 1, t = n + m + r * c * 2 + 2,
  memset(head, 0, sizeof head), idx = 1;
  for (int i = 1; i <= n; i++) add(s, i, 1), add(i, s, 0);
  for (int i = 1; i <= m; i++) add(i + n, t, 1), add(t, i + n, 0);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= r * c; j++)
      if (dist[(pla1[i][0] - 1) * c + pla1[i][1]][j] < 1000000000 &&
          1ll * dist[(pla1[i][0] - 1) * c + pla1[i][1]][j] * spe1[i] <= x)
        add(i, j + n + m, 1), add(j + n + m, i, 0);
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= r * c; j++)
      if (dist[(pla2[i][0] - 1) * c + pla2[i][1]][j] < 1000000000 &&
          1ll * dist[(pla2[i][0] - 1) * c + pla2[i][1]][j] * spe2[i] <= x)
        add(j + n + m + r * c, i + n, 1), add(i + n, j + n + m + r * c, 0);
  for (int i = 1; i <= r * c; i++)
    add(i + n + m, i + n + m + r * c, 1), add(i + n + m + r * c, i + n + m, 0);
  sum = 0;
  while (bfs()) memcpy(cur, head, sizeof head), sum += dfs(s, 1000000000);
  return sum == n;
}
int main() {
  scanf("%d%d%d%d", &r, &c, &n, &m);
  for (int i = 1; i <= r; i++) scanf("%s", str[i] + 1);
  for (int i = 1; i <= r; i++)
    for (int j = 1; j <= c; j++)
      if (str[i][j] == '.') many++;
  for (int i = 1; i <= r * c; i++)
    for (int j = 1; j <= r * c; j++)
      if (i != j) dist[i][j] = 1000000000;
  for (int i = 1; i < r; i++)
    for (int j = 1; j <= c; j++)
      if (str[i][j] == '.' && str[i + 1][j] == '.')
        dist[(i - 1) * c + j][i * c + j] = dist[i * c + j][(i - 1) * c + j] = 1;
  for (int i = 1; i <= r; i++)
    for (int j = 1; j < c; j++)
      if (str[i][j] == '.' && str[i][j + 1] == '.')
        dist[(i - 1) * c + j + 1][(i - 1) * c + j] =
            dist[(i - 1) * c + j][(i - 1) * c + j + 1] = 1;
  for (int k = 1; k <= r * c; k++)
    for (int i = 1; i <= r * c; i++)
      for (int j = 1; j <= r * c; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  if (abs(n - m) != 1 || many * 2 < n + m + 1) printf("-1\n"), exit(0);
  if (n > m)
    scanf("%d%d%d", &pla2[m + 1][0], &pla2[m + 1][1], &spe2[m + 1]);
  else
    scanf("%d%d%d", &pla1[n + 1][0], &pla1[n + 1][1], &spe1[n + 1]);
  for (int i = 1; i <= n; i++)
    scanf("%d%d%d", &pla1[i][0], &pla1[i][1], &spe1[i]);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &pla2[i][0], &pla2[i][1], &spe2[i]);
  if (n > m)
    m++;
  else
    n++;
  L = 0, R = 1ll * 1000000000 * 1000000000;
  while (L < R) {
    long long mid = (L + R) >> 1;
    if (check(mid))
      R = mid;
    else
      L = mid + 1;
  }
  printf("%lld\n", L == 1ll * 1000000000 * 1000000000 ? -1 : L);
}
