#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m, n1, n2;
char a[30][30];
long long b[2][500][3];
int c[30][30];
vector<pair<pair<int, int>, long long>> q;
int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
long long dis[30][30][30][30];
struct EDGE {
  int s, e, f, r;
  EDGE() {}
  EDGE(int s, int e, int f, int r) {
    this->s = s, this->e = e, this->f = f, this->r = r;
  }
};
vector<EDGE> edges;
vector<int> edge[20000];
int N;
int isgood(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }
void bfs(int x, int y) {
  int i, j, k;
  for (j = 0; j < n; j++)
    for (k = 0; k < m; k++) c[j][k] = 0, dis[x][y][j][k] = ((1ll << 62) - 1);
  q.clear();
  q.push_back(make_pair(make_pair(x, y), 0));
  dis[x][y][x][y] = 0;
  c[x][y] = 1;
  for (j = 0; j < q.size(); j++) {
    auto u = q[j];
    for (k = 0; k < 4; k++) {
      int nx = u.first.first + dir[k][0];
      int ny = u.first.second + dir[k][1];
      if (isgood(nx, ny) && c[nx][ny] == 0 && a[nx][ny] != '#') {
        c[nx][ny] = 1;
        dis[x][y][nx][ny] = u.second + 1;
        q.push_back(make_pair(make_pair(nx, ny), (long long)u.second + 1));
      }
    }
  }
}
void addedge(int s, int e, int f) {
  int u = edges.size();
  edges.push_back(EDGE(s, e, f, u + 1));
  edges.push_back(EDGE(e, s, 0, u));
  edge[s].push_back(u);
  edge[e].push_back(u + 1);
}
int num[20000];
vector<int> q2;
void dinicbfs() {
  int i, j, k;
  for (i = 0; i < N; i++) num[i] = -1;
  num[0] = 0;
  q2.clear();
  q2.push_back(0);
  for (i = 0; i < q2.size(); i++) {
    int now = q2[i];
    for (auto e : edge[now]) {
      EDGE u = edges[e];
      if (u.f && num[u.e] == -1) num[u.e] = num[now] + 1, q2.push_back(u.e);
    }
  }
}
int back(int now, int flow) {
  if (now == N - 1) {
    return flow;
  }
  for (auto e : edge[now]) {
    EDGE u = edges[e];
    if (!u.f || num[now] + 1 != num[u.e]) continue;
    int f = back(u.e, min(flow, u.f));
    if (f) {
      edges[e].f -= f;
      edges[edges[e].r].f += f;
      return f;
    }
  }
  num[now] = -1;
  return 0;
}
int param(long long x) {
  int i, j, k;
  edges.clear();
  for (i = 0; i < N; i++) edge[i].clear();
  for (i = 0; i < n1; i++) {
    addedge(0, 1 + i, 1);
    addedge(1 + n1 + n * m * 2 + i, N - 1, 1);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      addedge(n1 + 1 + (i * m + j) * 2, n1 + 1 + (i * m + j) * 2 + 1, 1);
    }
  }
  for (i = 0; i < n1; i++) {
    for (j = 0; j < n; j++) {
      for (k = 0; k < m; k++) {
        if (dis[b[0][i][0]][b[0][i][1]][j][k] != ((1ll << 62) - 1) &&
            (long long)dis[b[0][i][0]][b[0][i][1]][j][k] * b[0][i][2] <= x) {
          addedge(i + 1, n1 + 1 + (j * m + k) * 2, 1);
        }
        if (dis[b[1][i][0]][b[1][i][1]][j][k] != ((1ll << 62) - 1) &&
            (long long)dis[b[1][i][0]][b[1][i][1]][j][k] * b[1][i][2] <= x) {
          addedge(n1 + 1 + (j * m + k) * 2 + 1, n1 + 1 + n * m * 2 + i, 1);
        }
      }
    }
  }
  int cnt = 0;
  while (1) {
    dinicbfs();
    if (num[N - 1] == -1) break;
    while (1) {
      int u = back(0, ((1 << 30) - 1));
      cnt += u;
      if (!u) break;
    }
  }
  if (cnt == n1) return 1;
  return 0;
}
int main() {
  int i, j, k;
  scanf("%d%d%d%d", &n, &m, &n1, &n2);
  for (i = 0; i < n; i++) scanf("%s", a[i]);
  if (n1 == n2 + 1) {
    scanf("%I64d%I64d%I64d", &b[1][n2][0], &b[1][n2][1], &b[1][n2][2]);
  } else if (n1 + 1 == n2) {
    scanf("%I64d%I64d%I64d", &b[0][n1][0], &b[0][n1][1], &b[0][n1][2]);
  } else
    return printf("-1"), 0;
  for (i = 0; i < n1; i++)
    for (j = 0; j < 3; j++) scanf("%I64d", &b[0][i][j]);
  for (i = 0; i < n2; i++)
    for (j = 0; j < 3; j++) scanf("%I64d", &b[1][i][j]);
  n1 = n2 = max(n1, n2);
  for (i = 0; i < n1; i++) {
    b[0][i][0]--, b[0][i][1]--, b[1][i][0]--, b[1][i][1]--;
  }
  long long low = 0, high = (long long)((1 << 30) - 1) * n * m, mid;
  N = 2 + n1 + n1 + n * m * 2;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      bfs(i, j);
    }
  }
  while (low <= high) {
    mid = (low + high) / 2;
    if (param(mid))
      high = mid - 1;
    else
      low = mid + 1;
  }
  if (low == (long long)((1 << 30) - 1) * n * m + 1)
    printf("-1");
  else
    printf("%I64d", low);
  return 0;
}
