#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int oo = 2147483647;
const long long ool = 1ll << 60;
struct Edge {
  int from, to, flow;
  Edge() {}
  Edge(int _1, int _2, int _3) : from(_1), to(_2), flow(_3) {}
};
namespace Dinic {
int n, m, s, t, head[2000], nxt[1000000];
Edge es[1000000];
int Q[2000], hd, tl, vis[2000];
int cur[2000];
void init() {
  m = 0;
  memset(head, -1, sizeof(head));
  return;
}
void setn(int _) {
  n = _;
  return;
}
void AddEdge(int a, int b, int c) {
  es[m] = Edge(a, b, c);
  nxt[m] = head[a];
  head[a] = m++;
  es[m] = Edge(b, a, 0);
  nxt[m] = head[b];
  head[b] = m++;
  return;
}
bool BFS() {
  memset(vis, 0, sizeof(vis));
  vis[t] = 1;
  hd = tl = 0;
  Q[++tl] = t;
  while (hd != tl) {
    int u = Q[++hd];
    for (int i = head[u]; i != -1; i = nxt[i]) {
      Edge& e = es[i ^ 1];
      if (!vis[e.from] && e.flow) vis[e.from] = vis[u] + 1, Q[++tl] = e.from;
    }
  }
  return vis[s] > 1;
}
int DFS(int u, int a) {
  if (u == t || !a) return a;
  int flow = 0, f;
  for (int& i = cur[u]; i != -1; i = nxt[i]) {
    Edge& e = es[i];
    if (vis[e.to] == vis[u] - 1 && (f = DFS(e.to, min(a, e.flow)))) {
      flow += f;
      a -= f;
      e.flow -= f;
      es[i ^ 1].flow += f;
      if (!a) return flow;
    }
  }
  return flow;
}
int MaxFlow(int _s, int _t) {
  s = _s;
  t = _t;
  int flow = 0;
  while (BFS()) {
    for (int i = (1), mi = (n); i <= mi; i++) cur[i] = head[i];
    flow += DFS(s, oo);
  }
  return flow;
}
}  // namespace Dinic
char Map[25][25];
int CntP;
struct Point {
  int id;
  Point() : id(0) {}
  int p() { return id ? id : id = ++CntP; }
} boy[2000], girl[2000], In[25][25], Out[25][25], S, T;
int hd, tl, step[25][25], dx[4] = {0, 0, -1, 1}, dy[4] = {-1, 1, 0, 0};
pair<int, int> Q[25 * 25];
void bfs(int sx, int sy, int n, int m) {
  memset(step, -1, sizeof(step));
  step[sx][sy] = 0;
  hd = tl = 0;
  Q[++tl] = make_pair(sx, sy);
  while (hd < tl) {
    pair<int, int> u = Q[++hd], v;
    for (int i = (0), mi = (3); i <= mi; i++) {
      v = make_pair(u.first + dx[i], u.second + dy[i]);
      if (1 <= v.first && v.first <= n && 1 <= v.second && v.second <= m &&
          step[v.first][v.second] < 0 && Map[v.first][v.second] == '.')
        step[v.first][v.second] = step[u.first][u.second] + 1, Q[++tl] = v;
    }
  }
  return;
}
struct Info {
  int first, second, t;
  Info() {}
  Info(int _1, int _2, int _3) : first(_1), second(_2), t(_3) {}
} Boy[2000], Girl[2000];
int main() {
  int n = read(), m = read(), male = read(), female = read();
  for (int i = (1), mi = (n); i <= mi; i++) scanf("%s", Map[i] + 1);
  int ax = read(), ay = read(), at = read(), mxt = at;
  for (int i = (1), mi = (male); i <= mi; i++) {
    int first = read(), second = read(), t = read();
    Boy[i] = Info(first, second, t);
    mxt = max(mxt, t);
    if (Map[first][second] == '#') return puts("-1"), 0;
  }
  for (int i = (1), mi = (female); i <= mi; i++) {
    int first = read(), second = read(), t = read();
    Girl[i] = Info(first, second, t);
    mxt = max(mxt, t);
    if (Map[first][second] == '#') return puts("-1"), 0;
  }
  if (male == female || abs(male - female) > 1) return puts("-1"), 0;
  if (male < female)
    Boy[++male] = Info(ax, ay, at);
  else
    Girl[++female] = Info(ax, ay, at);
  int K = male;
  long long l = 0, r = ((long long)mxt * n * m << 1) + 1;
  while (l < r) {
    long long mid = l + r >> 1;
    Dinic::init();
    for (int i = (1), mi = (K); i <= mi; i++) {
      Dinic::AddEdge(S.p(), boy[i].p(), 1);
      int first = Boy[i].first, second = Boy[i].second, t = Boy[i].t;
      bfs(first, second, n, m);
      for (int a = (1), mi = (n); a <= mi; a++)
        for (int b = (1), mi = (m); b <= mi; b++)
          if (step[a][b] >= 0 && (long long)step[a][b] * t <= mid)
            Dinic::AddEdge(boy[i].p(), In[a][b].p(), 1);
    }
    for (int i = (1), mi = (K); i <= mi; i++) {
      Dinic::AddEdge(girl[i].p(), T.p(), 1);
      int first = Girl[i].first, second = Girl[i].second, t = Girl[i].t;
      bfs(first, second, n, m);
      for (int a = (1), mi = (n); a <= mi; a++)
        for (int b = (1), mi = (m); b <= mi; b++)
          if (step[a][b] >= 0 && (long long)step[a][b] * t <= mid)
            Dinic::AddEdge(Out[a][b].p(), girl[i].p(), 1);
    }
    for (int a = (1), mi = (n); a <= mi; a++)
      for (int b = (1), mi = (m); b <= mi; b++)
        Dinic::AddEdge(In[a][b].p(), Out[a][b].p(), 1);
    Dinic::setn(CntP);
    int flow = Dinic::MaxFlow(S.p(), T.p());
    if (flow < K)
      l = mid + 1;
    else
      r = mid;
  }
  printf("%I64d\n", l == ((long long)mxt * n * m << 1) + 1 ? -1 : l);
  return 0;
}
