#include <bits/stdc++.h>
using namespace std;
vector<int> g[5000];
int capacidad[5000][5000];
int llega[5000];
int anterior[5000];
int aumenta(int uant, int uini) {
  anterior[uini] = uant;
  llega[uini] = 1;
  queue<int> q;
  q.push(uini);
  while (not q.empty()) {
    int u = q.front();
    q.pop();
    vector<int> &ar = g[u];
    for (int i = 0; i < int(ar.size()); i++) {
      int v = ar[i];
      if (not llega[v] and capacidad[u][v]) {
        llega[v] = 1;
        anterior[v] = u;
        q.push(v);
        if (v == 1) {
          while (v != 0) {
            int antv = anterior[v];
            capacidad[antv][v]--;
            capacidad[v][antv]++;
            v = antv;
          }
          for (int i = 0; i < 5000; i++) llega[i] = 0;
          aumenta(0, 0);
          return 1;
        }
      }
    }
  }
  return 0;
}
void aumenta() {}
int n, m;
int cuantos[2];
int libre[50][50];
int visto[50][50];
int acum[50][50];
int ii[2][500], jj[2][500], tt[2][500];
int movi[] = {-1, 1, 0, 0};
int movj[] = {0, 0, -1, 1};
int acumula(int i, int j) {
  if (not libre[i][j]) return 0;
  if (visto[i][j]) return 0;
  visto[i][j] = 1;
  int c = acum[i][j];
  for (int k = 0; k < 4; k++) c += acumula(i + movi[k], j + movj[k]);
  return c;
}
struct elem {
  int gender, ind;
  int i, j;
  long long int t;
  elem() {}
  elem(int ingender, int inind, int ini, int inj, long long int intt) {
    gender = ingender;
    ind = inind;
    i = ini;
    j = inj;
    t = intt;
  }
};
void escribe(elem e) {
  cout << "(" << e.gender << "," << e.ind << "," << e.i << "," << e.j << ","
       << e.t << ")" << endl;
}
bool operator<(elem e1, elem e2) { return e1.t < e2.t; }
int main() {
  cin >> n >> m >> cuantos[0] >> cuantos[1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == '.') libre[i][j] = 1;
    }
  }
  int ib, jb, tb;
  cin >> ib >> jb >> tb;
  for (int d = 0; d < 2; d++) {
    for (int k = 0; k < cuantos[d]; k++) {
      cin >> ii[d][k] >> jj[d][k] >> tt[d][k];
      acum[ii[d][k]][jj[d][k]] += 1 - 2 * d;
    }
  }
  int acc = acumula(ib, jb);
  if (acc == 1) {
    ii[1][cuantos[1]] = ib;
    jj[1][cuantos[1]] = jb;
    tt[1][cuantos[1]] = tb;
    cuantos[1]++;
  } else if (acc == -1) {
    ii[0][cuantos[0]] = ib;
    jj[0][cuantos[0]] = jb;
    tt[0][cuantos[0]] = tb;
    cuantos[0]++;
  } else {
    cout << -1 << endl;
    exit(0);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (not visto[i][j]) {
        int c = acumula(i, j);
        if (c != 0) {
          cout << -1 << endl;
          exit(0);
        }
      }
    }
  }
  vector<elem> ve;
  for (int gender = 0; gender < 2; gender++) {
    for (int ind = 0; ind < cuantos[gender]; ind++) {
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) visto[i][j] = 0;
      vector<pair<int, int> > vinf;
      long long int tact = 0;
      vinf.push_back(pair<int, int>(ii[gender][ind], jj[gender][ind]));
      while (vinf.size()) {
        vector<pair<int, int> > nextvinf;
        for (int d = 0; d < int(vinf.size()); d++) {
          int i = vinf[d].first;
          int j = vinf[d].second;
          if (not libre[i][j]) continue;
          if (visto[i][j]) continue;
          visto[i][j] = 1;
          ve.push_back(elem(gender, ind, i, j, tact));
          for (int k = 0; k < 4; k++) {
            int nexti = i + movi[k];
            int nextj = j + movj[k];
            nextvinf.push_back(pair<int, int>(nexti, nextj));
          }
        }
        vinf = nextvinf;
        tact += tt[gender][ind];
      }
    }
  }
  for (int d = 0; d < cuantos[0]; d++) {
    g[0].push_back(1000 + d);
    capacidad[0][1000 + d] = 1;
    g[4000 + d].push_back(1);
    capacidad[4000 + d][1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int u = 2000 + i * 22 + j;
      int v = 3000 + i * 22 + j;
      g[u].push_back(v);
      g[v].push_back(u);
      capacidad[u][v] = 1;
    }
  }
  sort(ve.begin(), ve.end());
  int flujo = 0;
  aumenta(0, 0);
  for (int d = 0; d < int(ve.size()); d++) {
    elem &e = ve[d];
    int u, v;
    if (e.gender == 0) {
      u = 1000 + e.ind;
      v = 2000 + e.i * 22 + e.j;
    } else {
      u = 3000 + e.i * 22 + e.j;
      v = 4000 + e.ind;
    }
    g[u].push_back(v);
    g[v].push_back(u);
    capacidad[u][v] = 1;
    if (llega[u] and not llega[v]) flujo += aumenta(u, v);
    if (flujo == cuantos[0]) {
      cout << e.t << endl;
      exit(0);
    }
  }
  cout << -1 << endl;
}
