#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e3 + 10, inf = 1e9 + 1000;
long long adj[maxn][maxn];
long long dist[maxn][maxn];
long long q[maxn];
long long n, m;
long long sz = 0;
bool mark[maxn];
long long s, b, k, h;
long long a[maxn], x[maxn], f[maxn];
long long y[maxn], d[maxn];
long long bmatch[maxn];
long long kossher[maxn];
void bfs(long long root) {
  q[0] = root;
  sz = 1;
  memset(mark, 0, sizeof mark);
  mark[root] = true;
  for (long long i = 0; i < n; ++i) dist[root][i] = inf;
  dist[root][root] = 0;
  for (long long i = 0; i < sz; i++) {
    long long v = q[i];
    for (long long u = 0; u < n; u++)
      if (adj[v][u] && !mark[u]) {
        dist[root][u] = dist[root][v] + 1;
        q[sz++] = u;
        mark[u] = true;
      }
  }
}
bool dfs(long long v) {
  if (mark[v]) return false;
  mark[v] = true;
  for (long long u = 0; u < s; u++) {
    if (adj[v][u]) {
      if (kossher[u] < 0 || dfs(kossher[u])) {
        kossher[u] = v;
        bmatch[v] = u;
        return true;
      }
    }
  }
  return false;
}
long long max_matching() {
  memset(bmatch, -1, sizeof bmatch);
  memset(kossher, -1, sizeof kossher);
  memset(mark, 0, sizeof mark);
  long long ans = 0;
  bool fnd = true;
  while (fnd) {
    memset(mark, 0, sizeof mark);
    fnd = false;
    for (long long v = 0; v < b; v++)
      if (bmatch[v] == -1 && dfs(v)) {
        ans++;
        fnd = true;
      }
  }
  return ans;
}
int32_t main() {
  cin >> n >> m;
  while (m--) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    adj[v][u] = adj[u][v] = true;
  }
  for (long long i = 0; i < n; i++) bfs(i);
  cin >> s >> b >> k >> h;
  for (long long i = 0; i < s; i++) {
    cin >> x[i] >> a[i] >> f[i];
    x[i]--;
  }
  memset(adj, 0, sizeof adj);
  for (long long i = 0; i < b; i++) {
    cin >> y[i] >> d[i];
    y[i]--;
    for (long long j = 0; j < s; j++) {
      if (dist[y[i]][x[j]] <= f[j] && d[i] <= a[j]) adj[i][j] = true;
    }
  }
  cout << min(k * max_matching(), h * s) << endl;
}
