#include <bits/stdc++.h>
using namespace std;
const int SZ = 105;
const int SZ2 = 1005;
vector<int> graph[SZ];
vector<int> bigraph[SZ2];
int dist[SZ][SZ];
pair<int, pair<int, int> > attack[SZ2];
pair<int, int> base[SZ2];
int vst[SZ2];
int bb[SZ2];
int n, m;
int ss, b, kk, h;
int dfs(int x) {
  if (vst[x] == 1) return 0;
  vst[x] = 1;
  for (int nxt : bigraph[x]) {
    if (!bb[nxt] || dfs(bb[nxt])) {
      bb[nxt] = x;
      return 1;
    }
  }
  return 0;
}
int bmatch() {
  int xx = 0;
  for (int i = 1; i <= ss; i++) {
    memset(vst, 0, sizeof(vst));
    if (dfs(i)) xx++;
  }
  return xx;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      dist[i][j] = SZ;
    }
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
    if (x != y) {
      dist[x][y] = 1;
      dist[y][x] = 1;
    }
  }
  cin >> ss >> b >> kk >> h;
  for (int i = 1; i <= ss; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    attack[i] = {x, {y, z}};
  }
  for (int i = 1; i <= b; i++) {
    int x, y;
    cin >> x >> y;
    base[i] = {x, y};
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      if (i == k) continue;
      for (int j = 1; j <= n; j++) {
        if (j == k || j == i) continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        dist[j][i] = dist[i][j];
      }
    }
  }
  for (int i = 1; i <= ss; i++) {
    for (int j = 1; j <= b; j++) {
      if (attack[i].second.first >= base[j].second &&
          attack[i].second.second >= dist[attack[i].first][base[j].first]) {
        bigraph[i].push_back(j);
      }
    }
  }
  int atck = bmatch();
  cout << min((long long)kk * (long long)atck, (long long)ss * (long long)h);
  return 0;
}
