#include <bits/stdc++.h>
using namespace std;
int const MAX = 141;
int n, m, male, female;
char a[MAX][MAX];
struct Ono {
  int x, y, t;
  Ono(){};
  Ono(int x, int y, int t) : x(x), y(y), t(t){};
};
vector<Ono> males, females;
long long dm[MAX][MAX][MAX];
long long df[MAX][MAX][MAX];
long long const INF = 1e18;
struct Point {
  int x, y;
  long long d;
  Point(int x, int y, long long d) : x(x), y(y), d(d){};
  Point(){};
  bool operator<(const Point &z) const {
    if (d != z.d) return d < z.d;
    if (x != z.x) return x < z.x;
    return y < z.y;
  };
};
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool inside(int x, int y) {
  if (x < 1 || x > n) return 0;
  if (y < 1 || y > m) return 0;
  return 1;
}
void bfs(Ono ono, long long d[MAX][MAX]) {
  for (int i = 0; i <= MAX - 1; i++) {
    for (int j = 0; j <= MAX - 1; j++) {
      d[i][j] = INF;
    }
  }
  d[ono.x][ono.y] = 0;
  deque<pair<int, int> > deq;
  deq.push_back(make_pair(ono.x, ono.y));
  while ((int)deq.size()) {
    int x = deq.front().first;
    int y = deq.front().second;
    deq.pop_front();
    for (int o = 0; o <= 3; o++) {
      int nx = x + dx[o];
      int ny = y + dy[o];
      if (!inside(nx, ny)) continue;
      if (a[nx][ny] == '#') continue;
      if (d[nx][ny] != INF) continue;
      d[nx][ny] = d[x][y] + ono.t;
      deq.push_back(make_pair(nx, ny));
    }
  }
}
map<pair<int, int>, int> id;
int getid(int l, int x) {
  if (id.find(make_pair(l, x)) == id.end()) {
    int s = (int)id.size();
    id[make_pair(l, x)] = s;
  }
  return id[make_pair(l, x)];
}
int const M = 1e5 + 41;
vector<int> e[M];
vector<int> flow, cap, from, to;
void clear() {
  for (int i = 0; i <= M - 1; i++) {
    e[i].clear();
  }
  flow.clear();
  cap.clear();
  from.clear();
  to.clear();
  id.clear();
}
int S, T;
void pushedge(int x, int y) {
  e[x].push_back((int)flow.size());
  flow.push_back(0);
  cap.push_back(1);
  from.push_back(x);
  to.push_back(y);
  e[y].push_back((int)flow.size());
  flow.push_back(0);
  cap.push_back(0);
  from.push_back(y);
  to.push_back(x);
}
int u[M];
int C;
int by[M];
bool dfs(int x) {
  u[x] = C;
  if (x == T) return true;
  for (int z : e[x]) {
    int y = to[z];
    if (u[y] == C) continue;
    if (flow[z] == cap[z]) continue;
    by[y] = z;
    if (dfs(y)) return true;
  }
  return false;
}
void relax() {
  int v = T;
  while (v != S) {
    int id = by[v];
    flow[id]++;
    flow[(id ^ 1)]--;
    v = from[id];
  }
}
int maxflow(long long dist) {
  clear();
  S = getid(-1, -1);
  T = getid(5, -1);
  for (int i = 0; i <= (int)males.size() - 1; i++) {
    int id = getid(0, i);
    pushedge(S, id);
  }
  for (int i = 0; i <= (int)males.size() - 1; i++) {
    int id = getid(0, i);
    for (int x = 1; x <= n; x++) {
      for (int y = 1; y <= m; y++) {
        if (dm[i][x][y] <= dist) {
          int id2 = getid(1, (x - 1) * m + y);
          pushedge(id, id2);
        }
      }
    }
  }
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= m; y++) {
      int id1 = getid(1, (x - 1) * m + y);
      int id2 = getid(2, (x - 1) * m + y);
      pushedge(id1, id2);
    }
  }
  for (int i = 0; i <= (int)females.size() - 1; i++) {
    int id = getid(3, i);
    for (int x = 1; x <= n; x++) {
      for (int y = 1; y <= m; y++) {
        if (df[i][x][y] <= dist) {
          int id2 = getid(2, (x - 1) * m + y);
          pushedge(id2, id);
        }
      }
    }
  }
  for (int i = 0; i <= (int)females.size() - 1; i++) {
    int id1 = getid(3, i);
    int id2 = getid(4, i);
    pushedge(id1, id2);
  }
  for (int i = 0; i <= (int)females.size() - 1; i++) {
    int id = getid(4, i);
    pushedge(id, T);
  }
  int res = 0;
  while (1) {
    C++;
    if (!dfs(S)) break;
    relax();
    res++;
  }
  return res;
}
void solve() {
  for (int i = 0; i <= (int)males.size() - 1; i++) {
    bfs(males[i], dm[i]);
  }
  for (int i = 0; i <= (int)females.size() - 1; i++) {
    bfs(females[i], df[i]);
  }
  long long l = -1;
  long long r = INF * 2;
  while (r - l > 1) {
    long long h = (l + r) / 2;
    int resp = maxflow(h);
    if (resp == (int)males.size()) {
      r = h;
    } else {
      l = h;
    }
  }
  if (r == INF) r = -1;
  printf("%lld\n", r);
}
int main() {
  scanf("%d %d %d %d", &n, &m, &male, &female);
  for (int i = 1; i <= n; i++) {
    scanf(" %s", a[i] + 1);
  }
  int x, y, t;
  scanf("%d %d %d", &x, &y, &t);
  if (abs(male - female) != 1) {
    printf("-1\n");
    return 0;
  }
  if (male + 1 == female) {
    males.push_back(Ono(x, y, t));
  } else {
    females.push_back(Ono(x, y, t));
  }
  for (int i = 1; i <= male; i++) {
    int x, y, t;
    scanf("%d %d %d", &x, &y, &t);
    males.push_back(Ono(x, y, t));
  }
  for (int i = 1; i <= female; i++) {
    int x, y, t;
    scanf("%d %d %d", &x, &y, &t);
    females.push_back(Ono(x, y, t));
  }
  solve();
  return 0;
}
