#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
const int INF = 0x3f3f3f3f;
int s, b, h, k, n, m;
struct sp {
  int v, a, f;
} S[maxn];
struct base {
  int v, d;
} B[maxn];
int mx[maxn];
vector<int> g[maxn];
int used[maxn], link[maxn];
int w[101][101];
bool dfs(int x) {
  for (auto& u : g[x]) {
    if (!used[u]) {
      used[u] = true;
      if (link[u] == -1 || dfs(link[u])) {
        link[u] = x;
        return true;
      }
    }
  }
  return false;
}
int hungary() {
  int res = 0;
  memset(link, -1, sizeof(link));
  for (int i = 1; i <= s; ++i) {
    memset(used, false, sizeof(used));
    if (dfs(i)) ++res;
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    fill(w[i] + 1, w[i] + 1 + n, INF);
  }
  for (int i = 1; i <= n; i++) w[i][i] = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    w[a][b] = 1;
    w[b][a] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        w[j][k] = min(w[j][k], w[j][i] + w[i][k]);
      }
    }
  }
  scanf("%d%d%d%d", &s, &b, &k, &h);
  for (int i = 1; i <= s; i++) {
    scanf("%d%d%d", &S[i].v, &S[i].a, &S[i].f);
  }
  for (int i = 1; i <= b; i++) {
    scanf("%d%d", &B[i].v, &B[i].d);
  }
  for (int i = 1; i <= s; i++) {
    for (int j = 1; j <= b; j++) {
      int u = S[i].v, v = B[i].v;
      if (w[u][v] <= S[i].f && S[i].a >= B[j].d) g[i].push_back(j);
    }
  }
  int mx = hungary();
  long long ans = min(1ll * mx * k, 1ll * s * h);
  printf("%lld\n", ans);
  return 0;
}
