#include <bits/stdc++.h>
using namespace std;
bool vis[50][50];
string s;
long long int X[1000], Y[1000], T[1000];
vector<long long int> female, male;
long long int n, m, ma, fe;
long long int d[1005][50][50];
queue<pair<long long int, long long int> > q;
void bfs(long long int si) {
  d[si][X[si]][Y[si]] = 0;
  q.push(make_pair(X[si], Y[si]));
  while (q.size()) {
    long long int i = q.front().first;
    long long int j = q.front().second;
    q.pop();
    if (!vis[i + 1][j] && d[si][i + 1][j] > d[si][i][j] + T[si]) {
      d[si][i + 1][j] = d[si][i][j] + T[si];
      q.push(make_pair(i + 1, j));
    }
    if (!vis[i - 1][j] && d[si][i - 1][j] > d[si][i][j] + T[si]) {
      d[si][i - 1][j] = d[si][i][j] + T[si];
      q.push(make_pair(i - 1, j));
    }
    if (!vis[i][j + 1] && d[si][i][j + 1] > d[si][i][j] + T[si]) {
      d[si][i][j + 1] = d[si][i][j] + T[si];
      q.push(make_pair(i, j + 1));
    }
    if (!vis[i][j - 1] && d[si][i][j - 1] > d[si][i][j] + T[si]) {
      d[si][i][j - 1] = d[si][i][j] + T[si];
      q.push(make_pair(i, j - 1));
    }
  }
}
const long long int INFLL = 1e18;
vector<int> adj[2013];
int res[2013][2013];
int source = 2011, sink = 2012;
void AddEdge(int a, int b) {
  adj[a].push_back(b);
  adj[b].push_back(a);
  res[a][b] = 1;
}
int h[2013];
queue<int> frontier;
int visited[2013];
bool level() {
  for (int i = 0; i < 2013; i++) h[i] = 1e9;
  h[source] = 0;
  frontier.push(source);
  while (frontier.size() > 0) {
    int x = frontier.front();
    frontier.pop();
    for (int i : adj[x])
      if (res[x][i] && h[i] == 1e9) {
        h[i] = h[x] + 1;
        frontier.push(i);
      }
  }
  return (h[sink] != 1e9);
}
int dfs(int x) {
  if (x == sink) return 1;
  visited[x] = 1;
  int num = 0;
  for (int i : adj[x])
    if (!visited[i] && h[i] == h[x] + 1 && res[x][i] && dfs(i)) {
      res[x][i] -= 1;
      res[i][x] += 1;
      num += 1;
      if (x != source) return num;
    }
  return num;
}
int maxflow() {
  int flow = 0;
  while (true) {
    if (!level()) break;
    for (int i = 0; i < 2013; i++) visited[i] = 0;
    flow += dfs(source);
  }
  return flow;
}
bool check(long long int x) {
  for (int i = 0; i < 2013; i++) {
    adj[i].clear();
    for (int j = 0; j < 2013; j++) res[i][j] = 0;
  }
  source = 0;
  sink = 2 * n * m + ma + fe + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      AddEdge((i - 1) * m + j, (i - 1) * m + j + n * m);
  for (int k = 0; k < female.size(); k++) {
    AddEdge(0, 2 * n * m + k + 1);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++)
        if (d[female[k]][i][j] <= x)
          AddEdge(2 * n * m + k + 1, (i - 1) * m + j);
  }
  for (int k = 0; k < male.size(); k++) {
    AddEdge(2 * n * m + k + 1 + fe, 2 * n * m + ma + fe + 1);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++)
        if (d[male[k]][i][j] <= x)
          AddEdge((i - 1) * m + j + n * m, 2 * n * m + k + 1 + fe);
  }
  return (maxflow() == male.size());
}
long long int binsearch() {
  long long int l = 0, r = 1e15;
  if (!check(r)) return -1;
  long long int mid = (l + r) >> 1;
  while (r - l > 1) {
    if (check(mid))
      r = mid;
    else
      l = mid;
    mid = (l + r) >> 1;
  }
  while (!check(mid)) mid++;
  return mid;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 50; i++)
    for (int j = 0; j < 50; j++) vis[i][j] = 1;
  for (int i = 0; i < 1000; i++)
    for (int j = 0; j < 50; j++)
      for (int h = 0; h < 50; h++) d[i][j][h] = 1e18;
  cin >> n >> m >> ma >> fe;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 1; j <= m; j++) {
      if (s[j - 1] == '.') vis[i][j] = 0;
    }
  }
  if (abs(ma - fe) > 1) return cout << -1 << '\n', 0;
  long long int x, y, t;
  cin >> X[1] >> Y[1] >> T[1];
  if (ma > fe)
    female.push_back(1);
  else
    male.push_back(1);
  for (int i = 2; i <= ma + 1; i++)
    cin >> X[i] >> Y[i] >> T[i], male.push_back(i);
  for (int i = ma + 2; i <= fe + ma + 1; i++)
    cin >> X[i] >> Y[i] >> T[i], female.push_back(i);
  for (int i = 1; i <= ma + fe + 1; i++) bfs(i);
  ma = male.size();
  fe = female.size();
  long long int ans = binsearch();
  cout << ans << '\n';
  return 0;
}
