#include <bits/stdc++.h>
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt")
using namespace std;
struct mycomplex {
  double re, im;
  mycomplex(double a, double b) { re = a, im = b; }
  mycomplex() {}
};
mycomplex operator*(const mycomplex& a, const mycomplex& b) {
  return {a.re * b.re - a.im * b.im, a.im * b.re + a.re * b.im};
}
mycomplex operator-(const mycomplex& a, const mycomplex& b) {
  return {a.re - b.re, a.im - b.im};
}
mycomplex operator+(const mycomplex& a, const mycomplex& b) {
  return {a.re + b.re, a.im + b.im};
}
const long long INF = 1e18;
const long double PI = acos(-1);
const long double EPS = 1e-11;
const int MOD7 = 1000000007;
const int MOD9 = 1000000009;
long long mod = 998244353;
const int inf = 1e9;
mt19937 rnd(time(0) + 11239);
const int MAXN = 2e3;
struct edge {
  int a, b, cap;
};
vector<edge> e;
vector<int> g[MAXN];
int distp[MAXN];
void addedge(int a, int b, int cap) {
  g[a].push_back(e.size());
  e.push_back({a, b, cap});
  g[b].push_back(e.size());
  e.push_back({b, a, 0});
}
int s, t;
bool bfs() {
  fill(distp, distp + MAXN, inf);
  distp[s] = 0;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (int i : g[v]) {
      if (e[i].cap > 0) {
        int b = e[i].b;
        if (distp[b] > distp[v] + 1) {
          distp[b] = distp[v] + 1;
          q.push(b);
        }
      }
    }
  }
  return distp[t] != inf;
}
int ptr[MAXN];
int dfs(int v, int flow) {
  if (v == t) return flow;
  if (!flow) return 0;
  int sum = 0;
  for (; ptr[v] < g[v].size(); ++ptr[v]) {
    int b = e[g[v][ptr[v]]].b;
    int cap = e[g[v][ptr[v]]].cap;
    if (cap <= 0) continue;
    if (distp[b] != distp[v] + 1) continue;
    int x = dfs(b, min(flow, cap));
    int id = g[v][ptr[v]];
    e[id].cap -= x;
    e[id ^ 1].cap += x;
    flow -= x;
    sum += x;
  }
  return sum;
}
int dinic() {
  int ans = 0;
  while (1) {
    if (!bfs()) break;
    fill(ptr, ptr + MAXN, 0);
    int x = dfs(s, 1e9);
    if (!x) break;
    ans += x;
  }
  return ans;
}
int n, m, male, female;
vector<vector<char>> a;
const int MAXX = 22;
vector<pair<pair<int, int>, int>> ml, fml;
int d[MAXX][MAXX][MAXX][MAXX];
vector<int> dx{1, -1, 0, 0};
vector<int> dy{0, 0, 1, -1};
int getnum(int i, int j) { return ml.size() + fml.size() + 5 + i * m + j + 1; }
bool check(long long r) {
  for (int i = 0; i < MAXN; ++i) g[i].clear();
  e.clear();
  s = 0, t = 1;
  vector<vector<int>> mem(n, vector<int>(m));
  for (int ti = 0; ti < n; ++ti) {
    for (int tj = 0; tj < m; ++tj) {
      addedge(getnum(ti, tj), getnum(ti, tj) + n * m, 1);
    }
  }
  for (int i = 0; i < ml.size(); ++i) {
    addedge(s, i + 2, 1);
    for (int ti = 0; ti < n; ++ti) {
      for (int tj = 0; tj < m; ++tj) {
        if (d[ml[i].first.first][ml[i].first.second][ti][tj] == inf) continue;
        if ((long long)d[ml[i].first.first][ml[i].first.second][ti][tj] *
                ml[i].second <=
            r) {
          addedge(i + 2, getnum(ti, tj), 1);
        }
      }
    }
  }
  for (int j = 0; j < fml.size(); ++j) {
    addedge(ml.size() + 2 + j + 1, t, 1);
    for (int ti = 0; ti < n; ++ti) {
      for (int tj = 0; tj < m; ++tj) {
        if (d[fml[j].first.first][fml[j].first.second][ti][tj] == inf) continue;
        if ((long long)d[fml[j].first.first][fml[j].first.second][ti][tj] *
                fml[j].second <=
            r) {
          addedge(getnum(ti, tj) + n * m, j + 1 + ml.size() + 2, 1);
        }
      }
    }
  }
  return dinic() == max(male, female);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  srand(time(NULL));
  cin >> n >> m >> male >> female;
  a.resize(n, vector<char>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  if (abs(male - female) != 1) {
    cout << -1;
    return 0;
  }
  int r, c, t;
  cin >> r >> c >> t;
  if (male < female)
    ml.push_back({{r, c}, t});
  else
    fml.push_back({{r, c}, t});
  for (int j = 0; j < male; ++j) {
    cin >> r >> c >> t;
    ml.push_back({{r, c}, t});
  }
  for (int j = 0; j < female; ++j) {
    cin >> r >> c >> t;
    fml.push_back({{r, c}, t});
  }
  for (int i = 0; i < ml.size(); ++i) {
    ml[i].first.first--;
    ml[i].first.second--;
    fml[i].first.first--;
    fml[i].first.second--;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#') continue;
      queue<pair<int, int>> q;
      fill(*d[i][j], *d[i][j] + MAXX * MAXX, inf);
      d[i][j][i][j] = 0;
      q.push({i, j});
      while (q.size()) {
        auto v = q.front();
        q.pop();
        for (int k = 0; k < 4; ++k) {
          int nx = v.first + dx[k], ny = v.second + dy[k];
          if (nx >= 0 && nx < n && ny >= 0 && ny < m && a[nx][ny] == '.' &&
              d[i][j][nx][ny] > d[i][j][v.first][v.second] + 1) {
            d[i][j][nx][ny] = d[i][j][v.first][v.second] + 1;
            q.push({nx, ny});
          }
        }
      }
    }
  }
  long long l = -1, rr = 1e12 + 229;
  while (rr - l > 1) {
    long long mm = (l + rr) / 2;
    if (check(mm))
      rr = mm;
    else
      l = mm;
  }
  check(2);
  if (rr > 1e12)
    cout << -1;
  else
    cout << rr;
}
