#include <bits/stdc++.h>
using namespace std;
const int maxn = 179;
int dist[maxn][maxn];
vector<vector<int>> lr;
vector<vector<int>> rl;
vector<int> p;
bool used[1179];
bool dfs(int v) {
  used[v] = true;
  for (int u : lr[v]) {
    if (p[u] == -1 || (!used[p[u]] && dfs(p[u]))) {
      p[u] = v;
      return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++)
      dist[i][j] = numeric_limits<int>::max() / 2;
  for (int i = 0; i < (int)(n); i++) dist[i][i] = 0;
  for (int i = 0; i < (int)(m); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (u == v) continue;
    dist[u][v] = dist[v][u] = 1;
  }
  for (int k = 0; k < (int)(n); k++) {
    for (int i = 0; i < (int)(n); i++) {
      for (int j = 0; j < (int)(n); j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int s, b;
  long long k, h;
  cin >> s >> b >> k >> h;
  lr.resize(s);
  rl.resize(b);
  vector<int> xs(s), a(s), f(s);
  for (int i = 0; i < (int)(s); i++) {
    cin >> xs[i] >> a[i] >> f[i];
    xs[i]--;
  }
  vector<int> xb(b), d(b);
  for (int i = 0; i < (int)(b); i++) {
    cin >> xb[i] >> d[i];
    xb[i]--;
  }
  for (int i = 0; i < (int)(s); i++) {
    for (int j = 0; j < (int)(b); j++) {
      if (dist[xs[i]][xb[j]] <= f[i] && a[i] >= d[j]) {
        lr[i].push_back(j);
        rl[j].push_back(i);
      }
    }
  }
  p.resize(b, -1);
  int msz = 0;
  for (int i = 0; i < (int)(s); i++) {
    memset(used, 0, sizeof(used));
    if (dfs(i)) {
      msz++;
    }
  }
  long long mincost = min(msz * k, h * s);
  cout << mincost << endl;
  return 0;
}
