#include <bits/stdc++.h>
using namespace std;
long long n, m, k, h, s, b;
vector<vector<long long>> g1(1e2 + 7);
vector<vector<long long>> g2(1e3 + 7);
vector<vector<pair<long long, long long>>> v(1e2 + 7);
struct ZV {
  long long x, a, f;
};
vector<ZV> K;
vector<long long> used(1e3 + 7);
vector<long long> p(1e3 + 7);
void dfs(long long x, long long r, long long num) {
  if (r >= 0) used[x] = 1;
  if (r >= 0) {
    for (long long i = 0; i < v[x].size(); i++) {
      if (K[num].a >= v[x][i].second) {
        g2[num].push_back(v[x][i].first);
      }
    }
  } else
    return;
  for (long long i = 0; i < g1[x].size(); i++) {
    if (!used[g1[x][i]]) dfs(g1[x][i], r - 1, num);
  }
}
bool dfs2(long long x) {
  if (used[x]) return 0;
  used[x] = 1;
  for (long long i = 0; i < g2[x].size(); i++) {
    if (!p[g2[x][i]] || dfs2(p[g2[x][i]])) {
      return p[g2[x][i]] = x;
    }
  }
  return 0;
}
int32_t main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    g1[a].push_back(b);
    g1[b].push_back(a);
  }
  cin >> s >> b >> k >> h;
  K.resize(s + 1);
  for (long long i = 1; i < s + 1; i++) {
    cin >> K[i].x >> K[i].a >> K[i].f;
  }
  for (long long i = 1; i < b + 1; i++) {
    long long x, d;
    cin >> x >> d;
    v[x].push_back({i, d});
  }
  for (long long i = 1; i < s + 1; i++) {
    dfs(K[i].x, K[i].f, i);
    used.assign(1e3 + 7, 0);
  }
  long long count = 0;
  for (long long i = 1; i < s + 1; i++) {
    if (dfs2(i)) ++count;
    used.assign(1e3 + 7, 0);
  }
  cout << min(k * count, h * s);
}
