#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long flow;
  long long cap;
  long long next;
  long long inv;
};
const long long N = 1100000;
const long long inf = (long long)1e9;
vector<edge> v[N];
bool vis[N];
long long from[N];
long long RES_FLOW = 0;
vector<pair<long long, pair<long long, long long> > > edges;
vector<pair<long long, long long> > ness_edges;
void add_edge(long long x1, long long x2, long long x3) {
  edge x;
  x.flow = 0;
  x.cap = x3;
  x.next = x2;
  x.inv = v[x2].size();
  v[x1].push_back(x);
  x.flow = 0;
  x.cap = 0;
  x.next = x1;
  x.inv = v[x1].size() - 1;
  v[x2].push_back(x);
}
void init() {
  for (long long i = 0; i < N; i++) v[i].clear();
  RES_FLOW = 0;
  for (long long i = 0; i < ness_edges.size(); i++)
    add_edge(ness_edges[i].first, ness_edges[i].second, 1);
}
string a[50];
long long females[500][3];
long long males[500][3];
vector<pair<long long, pair<long long, long long> > > v2[800];
long long maxflow(long long n) {
  long long res_flow = 0;
  while (true) {
    queue<long long> q;
    for (long long i = 0; i < n; i++) {
      vis[i] = false;
    }
    q.push(0);
    while (!q.empty()) {
      long long x = q.front();
      q.pop();
      for (long long i = 0; i < v[x].size(); i++)
        if (!vis[v[x][i].next] && v[x][i].cap > v[x][i].flow) {
          q.push(v[x][i].next);
          vis[v[x][i].next] = true;
          from[v[x][i].next] = v[x][i].inv;
        }
    }
    if (!vis[n - 1]) break;
    long long dflow = inf;
    long long x = n - 1;
    while (x != 0) {
      long long a = v[x][from[x]].next;
      long long b = v[x][from[x]].inv;
      dflow = min(dflow, v[a][b].cap - v[a][b].flow);
      x = a;
    }
    x = n - 1;
    while (x != 0) {
      long long a = v[x][from[x]].next;
      long long b = v[x][from[x]].inv;
      v[a][b].flow += dflow;
      v[x][from[x]].flow -= dflow;
      x = a;
    }
    res_flow += dflow;
  }
  RES_FLOW += res_flow;
  return RES_FLOW;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  long long x1, x2, cm, cf;
  cin >> x1 >> x2 >> cm >> cf;
  for (long long i = 0; i < x1; i++) cin >> a[i];
  if (abs(cm - cf) != 1) {
    cout << "-1";
    return 0;
  }
  long long a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  long long maxt = a3;
  for (long long i = 0; i < cm; i++) {
    cin >> males[i][0] >> males[i][1] >> males[i][2];
    maxt = max(maxt, males[i][2]);
  }
  for (long long i = 0; i < cf; i++) {
    cin >> females[i][0] >> females[i][1] >> females[i][2];
    maxt = max(maxt, females[i][2]);
  }
  if (cm == cf + 1) {
    females[cf][0] = a1;
    females[cf][1] = a2;
    females[cf][2] = a3;
    cf = cm;
  } else {
    males[cm][0] = a1;
    males[cm][1] = a2;
    males[cm][2] = a3;
    cm = cf;
  }
  long long left = -1;
  long long right = maxt * 2 * (x1 + x2) + 1;
  for (long long i = 0; i < cm; i++) {
    ness_edges.push_back(make_pair(0, i + 1));
  }
  for (long long j = 0; j < x1; j++)
    for (long long k = 0; k < x2; k++) {
      ness_edges.push_back(
          make_pair(j * x2 + k + cm + 1, j * x2 + k + cm + 1 + x1 * x2));
    }
  for (long long i = 0; i < cm + cf; i++) {
    long long x3;
    long long x4;
    long long t;
    if (i < cm) {
      x3 = males[i][0];
      x4 = males[i][1];
      t = males[i][2];
    } else {
      x3 = females[i - cm][0];
      x4 = females[i - cm][1];
      t = females[i - cm][2];
    }
    x3--;
    x4--;
    queue<pair<pair<long long, long long>, long long> > q;
    q.push(make_pair(make_pair(x3, x4), 0));
    vector<pair<long long, long long> > dir;
    dir.push_back(make_pair(0, -1));
    dir.push_back(make_pair(0, 1));
    dir.push_back(make_pair(1, 0));
    dir.push_back(make_pair(-1, 0));
    bool visited[50][50];
    for (long long j = 0; j < x1; j++)
      for (long long k = 0; k < x2; k++) visited[j][k] = false;
    visited[x3][x4] = true;
    while (!q.empty()) {
      long long x3 = q.front().first.first;
      long long x4 = q.front().first.second;
      long long dd = q.front().second;
      if (i < cm) {
        edges.push_back(
            make_pair(dd * t, make_pair(i + 1, x3 * x2 + x4 + cm + 1)));
      } else {
        edges.push_back(
            make_pair(dd * t, make_pair(x3 * x2 + x4 + cm + 1 + x1 * x2,
                                        x1 * x2 * 2 + cm + 1 + i - cm)));
      }
      q.pop();
      for (long long j = 0; j < 4; j++) {
        long long nx3 = x3 + dir[j].first;
        long long nx4 = x4 + dir[j].second;
        if (nx3 >= 0 && nx3 < x1 && nx4 >= 0 && nx4 < x2)
          if (!visited[nx3][nx4] && a[nx3][nx4] == '.') {
            visited[nx3][nx4] = true;
            q.push(make_pair(make_pair(nx3, nx4), dd + 1));
          }
      }
    }
  }
  for (long long i = 0; i < cf; i++) {
    ness_edges.push_back(make_pair(x1 * x2 * 2 + cf + cm + 1 + i - cm,
                                   x1 * x2 * 2 + cm + 1 + cf * 2 - cm));
  }
  long long n = x1 * x2 * 2 + cm + 1 + cf * 2 - cm + 1;
  sort(edges.begin(), edges.end());
  long long now = 0;
  long long now2 = 0;
  while (now < edges.size()) {
    long long buf = edges[now].first;
    while (now < edges.size() && edges[now].first == buf) {
      v2[now2].push_back(edges[now]);
      now++;
    }
    if (v2[now2].size() >= 700) now2++;
  }
  now2++;
  long long sum = 0;
  for (long long i = 0; i < now2; i++) {
    sum += v2[i].size();
  }
  init();
  long long gr = 0;
  for (long long i = 0; i < now2; i++) {
    for (long long j = 0; j < v2[i].size(); j++)
      add_edge(v2[i][j].second.first, v2[i][j].second.second, 1);
    long long fl = maxflow(n);
    gr = i;
    if (fl == cf) break;
  }
  init();
  for (long long i = 0; i < gr; i++) {
    for (long long j = 0; j < v2[i].size(); j++)
      add_edge(v2[i][j].second.first, v2[i][j].second.second, 1);
  }
  now = 0;
  while (now < v2[gr].size()) {
    long long buf = v2[gr][now].first;
    while (now < v2[gr].size() && v2[gr][now].first == buf) {
      add_edge(v2[gr][now].second.first, v2[gr][now].second.second, 1);
      now++;
    }
    long long fl = maxflow(n);
    if (fl == cf) {
      cout << buf;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
