#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, S, T, fi2[N], a[305][305], ne[N * N], M, K, L, s, zz[N * N], x[N],
    f[N], t[N], X, d[N], y, match[N], z, ans, tot, fi[N];
void jb(int x, int y) {
  ne[++tot] = fi[x];
  fi[x] = tot;
  zz[tot] = y;
}
int dfs(int x) {
  for (int i = fi[x]; i; i = ne[i])
    if (!f[zz[i]]) {
      f[zz[i]] = 1;
      if (!match[zz[i]] || dfs(match[zz[i]])) {
        match[zz[i]] = x;
        return 1;
      }
    }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = i == j ? 0 : 1e9;
  while (m--) {
    scanf("%d%d", &X, &y);
    a[X][y] = a[y][X] = 1;
  }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) a[i][j] = min(a[i][k] + a[k][j], a[i][j]);
  scanf("%d%d%d%d", &s, &M, &K, &L);
  long long Ans = (long long)L * s;
  int num = 0;
  for (int i = 1; i <= s; i++) scanf("%d%d%d", &x[i], &f[i], &t[i]);
  for (int i = 1; i <= M; i++) {
    scanf("%d%d", &X, &y);
    for (int j = 1; j <= s; j++)
      if (a[x[j]][X] <= t[j] && f[j] >= y) jb(j, i);
  }
  for (int i = 1; i <= s; i++) {
    memset(f, 0, sizeof f);
    num += dfs(i);
  }
  for (int i = 1; i <= s; i++)
    Ans = min(Ans, (long long)min(num, i) * K + (long long)L * (s - i));
  printf("%lld\n", Ans);
}
