#include <bits/stdc++.h>
using namespace std;
const int maxn = 200050;
const long long mod = 1e9 + 7;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m;
int dis[105][105];
int s, b;
long long kk, hh;
struct ship {
  int x;
  long long f;
  long long a;
} ships[1050];
struct ene {
  int x;
  long long d;
} enes[1050];
int uN, vN;
int g[1050][1050];
int linker[1050];
int used[1050];
bool dfs(int u) {
  for (int v = 0; v < vN; v++) {
    if (g[u][v] && !used[v]) {
      used[v] = true;
      if (linker[v] == -1 || dfs(linker[v])) {
        linker[v] = u;
        return true;
      }
    }
  }
  return false;
}
int hungary() {
  int res = 0;
  memset(linker, -1, sizeof(linker));
  for (int u = 0; u < uN; u++) {
    memset(used, false, sizeof(used));
    if (dfs(u)) res++;
  }
  return res;
}
int main() {
  n = read();
  m = read();
  int u, v;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dis[i][j] = 1e7;
    }
    dis[i][i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    u = read();
    v = read();
    dis[u][v] = 1;
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (k == i || k == j || i == j) continue;
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  s = read();
  b = read();
  kk = read();
  hh = read();
  for (int i = 1; i <= s; i++) {
    ships[i].x = read();
    ships[i].a = read();
    ships[i].f = read();
  }
  for (int i = 1; i <= b; i++) {
    enes[i].x = read();
    enes[i].d = read();
  }
  uN = s;
  vN = b;
  for (int i = 1; i <= s; i++) {
    for (int j = 1; j <= b; j++) {
      if (ships[i].a >= enes[j].d && dis[ships[i].x][ships[j].x] <= ships[i].f)
        g[i - 1][j - 1] = 1;
    }
  }
  long long ans = min((long long)s * hh, kk * hungary());
  cout << ans;
  return 0;
}
