#include <bits/stdc++.h>
using namespace std;
vector<int> cand;
vector<int> prime(1000005);
vector<long long> primes;
void SieveOfEratosthenes(int n) {
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == 0) {
      for (int i = p * p; i <= n; i += p)
        if (prime[i] == 0) prime[i] = p;
    }
  }
}
long long power(long long x, long long y) {
  long long res = 1ll;
  x = x % 1000000007;
  if (x == 0ll) return 0;
  while (y > 0ll) {
    if (y & 1ll) res = (res * x) % 1000000007;
    y = y >> 1ll;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long add(long long x, long long y) {
  x += y;
  while (x >= 1000000007) x -= 1000000007;
  while (x < 0) x += 1000000007;
  return x;
}
long long mul(long long x, long long y) { return (x * 1ll * y) % 1000000007; }
long long binpow(long long x, long long y) {
  long long z = 1ll;
  while (y) {
    if (y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1ll;
  }
  return z;
}
long long inv(long long x) { return binpow(x, 1000000007 - 2); }
long long divide(long long x, long long y) { return mul(x, inv(y)); }
long long fact[2000006];
void precalc() {
  fact[0] = 1;
  for (long long i = 1; i < 2000006; i++) fact[i] = mul(fact[i - 1], i);
}
long long C(long long n, long long k) {
  if (n == 0) return 1;
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
long long sub(long long A, long long B) {
  return (A - B + 1000000007) % 1000000007;
}
long long maxival(long long v, long long tl, long long tr, long long l,
                  long long r, long long segtree[]) {
  if (l > r) return LLONG_MAX;
  if (l == tl && r == tr) return segtree[v];
  long long tm = (tl + tr) / 2;
  auto x1 = maxival(2 * v, tl, tm, l, min(r, tm), segtree);
  auto x2 = maxival(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, segtree);
  return min(x1, x2);
}
long long updateval(long long v, long long tl, long long tr, long long pos,
                    long long newval, long long segtree[]) {
  if (tl == tr) {
    segtree[v] = newval;
    return newval;
  } else {
    long long tm = (tl + tr) / 2;
    long long x;
    if (pos <= tm)
      x = updateval(2 * v, tl, tm, pos, newval, segtree);
    else
      x = updateval(2 * v + 1, tm + 1, tr, pos, newval, segtree);
    segtree[v] = min(segtree[2 * v], segtree[2 * v + 1]);
    return segtree[v];
  }
}
vector<long long> adj[1005];
vector<vector<long long>> capacity(1005, vector<long long>(1005, 0));
vector<long long> used(1005, 0);
vector<long long> mt(1005, 0);
long long s, b;
bool dfs(long long x) {
  if (used[x]) return false;
  used[x] = 1;
  for (long long y = 0; y < b; y++) {
    if (!capacity[x][y]) continue;
    if (mt[y] == -1 || dfs(mt[y])) {
      mt[y] = x;
      return true;
    }
  }
  return false;
}
long long kuhn() {
  for (long long i = 0; i < b; i++) mt[i] = -1;
  long long res = 0;
  for (long long i = 0; i < s; i++) {
    if (dfs(i)) {
      res++;
      for (int j = 0; j < s; j++) used[j] = 0;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(5);
  int t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<vector<long long>> dis(n, vector<long long>(n, INT_MAX));
    long long i, j, kk;
    for (i = 1; i <= m; i++) {
      long long u, v;
      cin >> u >> v;
      u--;
      v--;
      dis[u][v] = 1;
      dis[v][u] = 1;
    }
    long long k, h;
    cin >> s >> b >> k >> h;
    vector<vector<long long>> ships(s, vector<long long>(3, 0));
    for (i = 1; i <= s; i++) {
      long long x, a, f;
      cin >> x >> a >> f;
      x--;
      ships[i - 1] = {x, a, f};
    }
    vector<vector<long long>> bases(b, vector<long long>(2, 0));
    for (i = 1; i <= b; i++) {
      long long x, d;
      cin >> x >> d;
      x--;
      bases[i - 1] = {x, d};
    }
    for (i = 0; i < n; i++) {
      dis[i][i] = 0;
      for (j = 0; j < n; j++) {
        for (kk = 0; kk < n; kk++) {
          if (dis[j][i] + dis[i][kk] < dis[j][kk])
            dis[j][kk] = dis[j][i] + dis[i][kk];
        }
      }
    }
    for (i = 0; i < s; i++) {
      for (j = 0; j < b; j++) {
        if (dis[ships[i][0]][bases[j][0]] > ships[i][2]) continue;
        if (ships[i][1] < bases[j][1]) continue;
        adj[i].push_back(j);
        capacity[i][j]++;
      }
    }
    long long ans = kuhn();
    cout << min(ans * k, s * h) << "\n";
  }
  return 0;
}
