#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
struct Edge {
  int u, v;
  long long cap[2], flow;
};
vector<int> d, act;
bool bfs(int s, int t, vector<vector<int> >& adj, vector<Edge>& E) {
  queue<int> Q;
  d = vector<int>(adj.size(), -1);
  d[t] = 0;
  Q.push(t);
  while (not Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < int(adj[u].size()); ++i) {
      int e = adj[u][i], v = ((E[e].u == u) ? E[e].v : E[e].u);
      if (((E[e].u == v) ? E[e].cap[0] - E[e].flow : E[e].cap[1] + E[e].flow) >
              0 and
          d[v] == -1) {
        d[v] = d[u] + 1;
        Q.push(v);
      }
    }
  }
  return d[s] >= 0;
}
long long dfs(int u, int t, long long bot, vector<vector<int> >& adj,
              vector<Edge>& E) {
  if (u == t) return bot;
  for (; act[u] < int(adj[u].size()); ++act[u]) {
    int e = adj[u][act[u]];
    if (((E[e].u == u) ? E[e].cap[0] - E[e].flow : E[e].cap[1] + E[e].flow) >
            0 and
        d[u] == d[((E[e].u == u) ? E[e].v : E[e].u)] + 1) {
      long long inc = dfs(((E[e].u == u) ? E[e].v : E[e].u), t,
                          min(bot, ((E[e].u == u) ? E[e].cap[0] - E[e].flow
                                                  : E[e].cap[1] + E[e].flow)),
                          adj, E);
      if (inc) {
        E[e].flow += ((E[e].u == u) ? (inc) : (-(inc)));
        return inc;
      }
    }
  }
  return 0;
}
long long maxflow(int s, int t, vector<vector<int> >& adj, vector<Edge>& E) {
  for (int i = 0; i < int(E.size()); ++i) E[i].flow = 0;
  long long flow = 0, bot;
  while (bfs(s, t, adj, E)) {
    act = vector<int>(adj.size(), 0);
    while ((bot = dfs(s, t, INF, adj, E))) flow += bot;
  }
  return flow;
}
void addEdge(int u, int v, vector<vector<int> >& G, vector<Edge>& E) {
  Edge e;
  e.u = u;
  e.v = v;
  e.cap[0] = 1;
  e.cap[1] = 0;
  e.flow = 0;
  E.push_back(e);
  G[u].push_back(E.size() - 1);
  G[v].push_back(E.size() - 1);
}
struct ship {
  int x, a, f;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  long long D[n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) D[i][j] = INF;
    D[i][i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    D[u][v] = 1;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (D[i][j] > D[i][k] + D[k][j]) D[i][j] = D[i][k] + D[k][j];
      }
    }
  }
  int s, b, k, h;
  cin >> s >> b >> k >> h;
  vector<vector<int> > G(s + b + 2);
  vector<Edge> E;
  int src = s + b, sink = s + b + 1;
  for (int i = 0; i < s; ++i) addEdge(src, i, G, E);
  for (int i = 0; i < b; ++i) addEdge(s + i, sink, G, E);
  vector<ship> ss(s);
  for (int i = 0; i < s; ++i) {
    cin >> ss[i].x >> ss[i].a >> ss[i].f;
    --ss[i].x;
  }
  for (int i = 0; i < b; ++i) {
    int x, def;
    cin >> x >> def;
    --x;
    for (int j = 0; j < s; ++j) {
      if (ss[j].a >= def and ss[j].f >= D[ss[j].x][x]) addEdge(j, s + i, G, E);
    }
  }
  long long flow = maxflow(src, sink, G, E);
  long long best = INF;
  for (long long i = 0; i <= s; ++i) {
    best = min(best, i * h + (flow - max(0LL, i - (s - flow))) * k);
  }
  cout << best << endl;
}
