#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 2205;
bool vis[maxn];
int vlink[maxn], ulink[maxn], n1, a[maxn], f[maxn], pos[maxn];
vector<int> E[maxn];
int g[maxn][maxn];
bool dfs(int u) {
  for (int j = 0; j < E[u].size(); j++) {
    int i = E[u][j];
    if (!vis[i]) {
      vis[i] = true;
      if (vlink[i] == -1 || dfs(vlink[i])) {
        vlink[i] = u;
        ulink[u] = i;
        return true;
      }
    }
  }
  return false;
}
int hungry() {
  int ret = 0;
  memset(ulink, -1, sizeof(ulink));
  memset(vlink, -1, sizeof(vlink));
  for (int i = 1; i <= n1; i++) {
    memset(vis, 0, sizeof(vis));
    if (dfs(i)) ret++;
  }
  return ret;
}
int main() {
  int n, m, u, v, s, b, k, h, x, d;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j)
        g[i][j] = 0;
      else
        g[i][j] = INF;
    }
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    g[u][v] = 1, g[v][u] = 1;
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  cin >> n1 >> b >> k >> h;
  for (int i = 1; i <= n1; i++) {
    scanf("%d%d%d", pos + i, a + i, f + i);
  }
  for (int i = 1; i <= b; i++) {
    scanf("%d%d", &x, &d);
    for (int j = 1; j <= n1; j++) {
      int tmp = g[x][pos[j]];
      if (tmp <= f[j] && a[j] >= d) {
        E[j].emplace_back(i + n1);
      }
    }
  }
  hungry();
  vector<int> ans;
  for (int i = 1; i <= n1; i++) {
    if (ulink[i] != -1) {
      ans.emplace_back(k);
    } else
      ans.emplace_back(0);
  }
  sort(ans.begin(), ans.end());
  long long sum = 0;
  for (int i = 0; i < ans.size(); i++) sum += ans[i];
  long long fuck = sum, tot = 0;
  for (int i = 0; i < ans.size(); i++) {
    tot += h;
    tot -= ans[i];
    fuck = min(fuck, sum + tot);
  }
  cout << fuck;
  return 0;
}
