#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int maxm = 500005;
const int maxn = 2005;
char ma[maxn][maxn];
struct node {
  int r, c, t;
  node() {}
  node(int _r, int _c, int _t) : r(_r), c(_c), t(_t) {}
};
vector<node> males, females;
struct Ed {
  int u, v, nx, c;
  Ed() {}
  Ed(int _u, int _v, int _nx, int _c) : u(_u), v(_v), nx(_nx), c(_c) {}
} E[maxm << 1];
int edtot;
int G[maxn], cur[maxn];
void addedge(int u, int v, int c) {
  E[edtot] = Ed(u, v, G[u], c);
  G[u] = edtot++;
  E[edtot] = Ed(v, u, G[v], 0);
  G[v] = edtot++;
}
int go[25][25][25][25];
int vis[25][25];
void BFS(int X, int Y) {
  static queue<pair<int, int> > Q;
  Q.push(make_pair(X, Y));
  go[X][Y][X][Y] = 0;
  memset(vis, 0, sizeof(vis));
  vis[X][Y] = 1;
  static int tx[] = {-1, 1, 0, 0}, ty[] = {0, 0, -1, 1};
  while (!Q.empty()) {
    int x = Q.front().first, y = Q.front().second;
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int first = x + tx[i], second = y + ty[i];
      if (ma[first][second] == '.' && !vis[first][second]) {
        vis[first][second] = 1;
        Q.push(make_pair(first, second));
        go[X][Y][first][second] = go[X][Y][x][y] + 1;
      }
    }
  }
}
int level[maxn], s, t;
bool bfs() {
  static int que[maxn];
  int qh(0), qt(0);
  memset(level, 0, sizeof(level));
  level[que[++qt] = s] = 1;
  while (qh != qt) {
    int x = que[++qh];
    for (int i = G[x]; i != -1; i = E[i].nx)
      if (!level[E[i].v] && E[i].c) {
        level[que[++qt] = E[i].v] = level[x] + 1;
      }
  }
  return !!level[t];
}
int dfs(int u, int rm) {
  if (u == t) return rm;
  int rm1 = rm;
  for (int &i = cur[u]; i != -1; i = E[i].nx) {
    if (level[E[i].v] == level[u] + 1 && E[i].c) {
      int flow = dfs(E[i].v, min(rm, E[i].c));
      E[i].c -= flow, E[i ^ 1].c += flow;
      if ((rm -= flow) == 0) break;
    }
  }
  if (rm1 == rm) level[u] = 0;
  return rm1 - rm;
}
int main() {
  int n, m, male, female;
  scanf("%d%d%d%d", &n, &m, &male, &female);
  for (int i = 1; i <= n; i++) scanf("%s", ma[i] + 1);
  memset(go, 0x3f, sizeof(go));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (ma[i][j] == '.') {
        BFS(i, j);
      }
  int r, c, T;
  scanf("%d%d%d", &r, &c, &T);
  males.resize(1);
  females.resize(1);
  if (male < female) {
    males.emplace_back(r, c, T);
  } else {
    females.emplace_back(r, c, T);
  }
  for (int i = 1; i <= male; i++) {
    scanf("%d%d%d", &r, &c, &T);
    males.emplace_back(r, c, T);
  }
  for (int i = 1; i <= female; i++) {
    scanf("%d%d%d", &r, &c, &T);
    females.emplace_back(r, c, T);
  }
  male = males.size() - 1;
  female = females.size() - 1;
  if (male != female) {
    puts("-1");
    return 0;
  }
  s = female + male + 2 * n * m + 1;
  t = s + 1;
  long long low = -1, high = INF;
  bool flag = false;
  while (low < high - 1) {
    long long mid = (low + high) >> 1;
    edtot = 0;
    memset(G, -1, sizeof(G));
    for (int i = 1; i <= female; i++) {
      addedge(s, i, 1);
    }
    for (int i = 1; i <= female; i++) {
      for (int j = 1; j <= n; j++)
        for (int k = 1; k <= m; k++) {
          int tmp = go[females[i].r][females[i].c][j][k];
          if (tmp != inf && 1ll * tmp * females[i].t <= mid) {
            addedge(i, female + (j - 1) * m + k, 1);
          }
        }
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        addedge(female + (i - 1) * m + j, female + n * m + (i - 1) * m + j, 1);
      }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        for (int k = 1; k <= male; k++) {
          int tmp = go[males[k].r][males[k].c][i][j];
          if (tmp != inf && 1ll * tmp * males[k].t <= mid) {
            addedge(female + n * m + (i - 1) * m + j, female + 2 * n * m + k,
                    1);
          }
        }
      }
    for (int i = 1; i <= male; i++) {
      addedge(female + 2 * n * m + i, t, 1);
    }
    int ans = 0;
    while (bfs()) memcpy(cur, G, sizeof(G)), ans += dfs(s, inf);
    if (ans != male) {
      low = mid;
    } else {
      high = mid;
      flag = true;
    }
  }
  if (!flag)
    puts("-1");
  else
    printf("%I64d\n", high);
  return 0;
}
