#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 7, mod = 1e9 + 7;
int odl[N][N];
vector<int> G[N];
int match_left[N], match_right[N];
int x[N], a[N], f[N];
int n, m, s, b, h, k;
bool odw[N];
bool dfsMatch(int v) {
  if (odw[v] == true) return false;
  odw[v] = true;
  for (auto u : G[v]) {
    if (match_right[u] == -1 || dfsMatch(match_right[u])) {
      match_right[u] = v;
      match_left[v] = u;
      return true;
    }
  }
  return false;
}
long long match() {
  for (int i = 1; i <= max(s, b); i++) {
    match_right[i] = -1;
    match_left[i] = -1;
  }
  bool any;
  int ans = 0;
  do {
    any = false;
    for (int i = 0; i <= s; i++) odw[i] = false;
    for (int i = 1; i <= s; i++) {
      if (!odw[i] && match_left[i] == -1 && dfsMatch(i)) {
        any = true;
        ans++;
      }
    }
  } while (any);
  return ans;
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      odl[i][j] = 1e9 + 2137;
    }
  }
  for (int i = 0; i < m; i++) {
    int c, b;
    cin >> c >> b;
    odl[c][b] = odl[b][c] = 1;
  }
  for (int i = 1; i <= n; i++) {
    odl[i][i] = 0;
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        odl[i][j] = min(odl[i][j], odl[i][k] + odl[k][j]);
      }
    }
  }
  cin >> s >> b >> k >> h;
  long long ans = (long long)h * s;
  for (int i = 0; i < s; i++) {
    cin >> x[i] >> a[i] >> f[i];
  }
  for (int i = 0; i < b; i++) {
    int xx, d;
    cin >> xx >> d;
    for (int j = 0; j < s; j++) {
      if (odl[x[j]][xx] <= f[j] && a[j] >= d) {
        G[j + 1].push_back(i + 1);
      }
    }
  }
  ans = min(ans, match() * k);
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int qwe = 1;
  for (int i = 1; i <= qwe; i++) {
    solve();
  }
}
