#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long fpow(long long n, long long k, int p = (int)1e9 + 7) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
void addmod(int& a, int val, int p = (int)1e9 + 7) {
  if ((a = a + val) >= p) a -= p;
}
template <class T>
void setmin(T& a, T val) {
  a = min(a, val);
}
template <class T>
void setmax(T& a, T val) {
  a = max(a, val);
}
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = 2 * acos((long double)0);
struct Dinic {
  int n, s, t, E, adj[1000010], flow[1000010], cap[1000010], next[1000010],
      last[10010], run[10010], level[10010], que[10010];
  void init(int _n, int _s, int _t) {
    n = _n;
    s = _s;
    t = _t;
    E = 0;
    for (int i = 0; i <= n; i++) last[i] = -1;
  }
  void add(int u, int v, int c1, int c2) {
    adj[E] = v;
    flow[E] = 0;
    cap[E] = c1;
    next[E] = last[u];
    last[u] = E++;
    adj[E] = u;
    flow[E] = 0;
    cap[E] = c2;
    next[E] = last[v];
    last[v] = E++;
  }
  bool bfs() {
    for (int i = 0; i <= n; i++) level[i] = -1;
    level[s] = 0;
    int qsize = 0;
    que[qsize++] = s;
    for (int i = 0; i < qsize; i++) {
      for (int u = que[i], e = last[u]; e != -1; e = next[e]) {
        int v = adj[e];
        if (flow[e] < cap[e] && level[v] == -1) {
          level[v] = level[u] + 1;
          que[qsize++] = v;
        }
      }
    }
    return level[t] != -1;
  }
  int dfs(int u, int bot) {
    if (u == t) return bot;
    for (int& e = run[u]; e != -1; e = next[e]) {
      int v = adj[e], delta = 0;
      if (level[v] == level[u] + 1 && flow[e] < cap[e] &&
          (delta = dfs(v, min(bot, cap[e] - flow[e]))) > 0) {
        flow[e] += delta;
        flow[e ^ 1] -= delta;
        return delta;
      }
    }
    return 0;
  }
  int maxflow() {
    int total = 0;
    while (bfs()) {
      for (int i = 0; i <= n; i++) run[i] = last[i];
      for (int delta = dfs(s, 1000000000); delta > 0;
           delta = dfs(s, 1000000000))
        total += delta;
    }
    return total;
  }
} dinic;
const int maxn = 30;
int n, m, k, l;
int a[maxn][maxn];
vector<pair<int, int> > cor[2];
int id[maxn][maxn];
int dis[maxn * maxn][maxn * maxn];
void solve() {
  scanf("%d%d%d%d", &n, &m, &k, &l);
  if (abs(k - l) != 1) {
    printf("-1");
    return;
  }
  int d = max(k, l);
  for (int i = (0); i < (n); i++) {
    char s[maxn];
    scanf("%s", s);
    for (int j = (0); j < (m); j++) a[i][j] = s[j] == '.';
  }
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (m); j++) id[i][j] = i * m + j;
  int r, c, t;
  scanf("%d%d%d", &r, &c, &t);
  r--;
  c--;
  if (k < l)
    cor[0].push_back(make_pair(id[r][c], t));
  else
    cor[1].push_back(make_pair(id[r][c], t));
  for (int i = (0); i < (k); i++) {
    scanf("%d%d%d", &r, &c, &t);
    r--;
    c--;
    cor[0].push_back(make_pair(id[r][c], t));
  }
  for (int i = (0); i < (l); i++) {
    scanf("%d%d%d", &r, &c, &t);
    r--;
    c--;
    cor[1].push_back(make_pair(id[r][c], t));
  }
  memset(dis, 0x3f, sizeof(dis));
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (m); j++)
      if (a[i][j]) {
        dis[id[i][j]][id[i][j]] = 0;
        if (i && a[i - 1][j]) {
          dis[id[i][j]][id[i - 1][j]] = 1;
        }
        if (j && a[i][j - 1]) {
          dis[id[i][j]][id[i][j - 1]] = 1;
        }
        if (a[i + 1][j]) {
          dis[id[i][j]][id[i + 1][j]] = 1;
        }
        if (a[i][j + 1]) {
          dis[id[i][j]][id[i][j + 1]] = 1;
        }
      }
  for (int k = (0); k < (n * m); k++)
    for (int i = (0); i < (n * m); i++)
      for (int j = (0); j < (n * m); j++) {
        setmin(dis[i][j], dis[i][k] + dis[k][j]);
      }
  long long lo = 0, hi = LINF;
  while (lo < hi) {
    long long mid = (lo + hi) >> 1;
    int sr = 2 * (d + n * m), sk = 2 * (d + n * m) + 1;
    dinic.init(2 * (d + n * m) + 2, sr, sk);
    for (int i = (0); i < (d); i++) {
      dinic.add(sr, i, 1, 0);
      dinic.add(i + d, sk, 1, 0);
      int u = cor[0][i].first;
      int x = cor[0][i].second;
      int v = cor[1][i].first;
      int y = cor[1][i].second;
      for (int j = (0); j < (n * m); j++) {
        if (dis[u][j] < 1000000000 && (long long)x * dis[u][j] <= mid) {
          dinic.add(i, j + 2 * d, 1, 0);
        }
        if (dis[j][v] < 1000000000 && (long long)y * dis[j][v] <= mid) {
          dinic.add(j + 2 * d + n * m, i + d, 1, 0);
        }
      }
    }
    for (int i = (0); i < (n * m); i++) {
      dinic.add(i + 2 * d, i + 2 * d + n * m, 1, 0);
    }
    if (dinic.maxflow() < d)
      lo = mid + 1;
    else
      hi = mid;
  }
  if (lo == LINF) lo = -1;
  printf("%I64d", lo);
}
int main() {
  solve();
  return 0;
}
