#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
#pragma GCC push_options
#pragma GCC pop_options
#pragma GCC reset_options
#pragma GCC optimize("O3")
const double eps = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const long long LINF = 100000000000000LL;
const double DINF = numeric_limits<double>::infinity();
const long long MOD = 1000000007;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const double PI = 3.141592653589793;
inline void fastll(long long &input_number) {
  input_number = 0;
  int ch = getchar_unlocked();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar_unlocked();
  }
  while (ch >= '0' && ch <= '9') {
    input_number = (input_number << 3) + (input_number << 1) + ch - '0';
    ch = getchar_unlocked();
  }
  input_number *= sign;
}
inline void open(string a) {
  freopen((a + ".in").c_str(), "r", stdin);
  freopen((a + ".out").c_str(), "w", stdout);
}
inline void fasterios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
struct ShipDT {
  long long pos, att, fuel, price, profit;
};
struct BaseDT {
  long long pos, def, price;
};
struct dtE {
  long long power_, idx;
  bool type;
  bool operator<(const dtE &other) const {
    if (power_ != other.power_) return power_ < other.power_;
    return type > other.type;
  }
};
long long n, m;
long long dist[105][105];
long long CurMaxgold[105];
vector<dtE> events;
long long ShipN, BaseN, DepM;
ShipDT ship[100005];
BaseDT base[100005];
struct dt {
  long long to, cap, backidx;
};
struct dta {
  long long pos, step;
};
long long ans;
long long s, e;
long long st[200005];
long long level[200005];
queue<dta> antri;
vector<dt> edge[200005];
void make_edge(long long u, long long v, long long capto, long long backcap) {
  long long szu = edge[u].size();
  long long szv = edge[v].size();
  edge[u].push_back({v, capto, szv});
  edge[v].push_back({u, backcap, szu});
  return;
}
void bfs(dta now) {
  for (int i = 0; i < edge[now.pos].size(); i++) {
    long long nx = edge[now.pos][i].to;
    if (level[nx]) continue;
    if (edge[now.pos][i].cap == 0) continue;
    level[nx] = now.step + 1;
    antri.push({nx, now.step + 1});
  }
  return;
}
long long maxflow(long long pos, long long bcap) {
  if (pos == e) return bcap;
  for (; st[pos] < edge[pos].size(); st[pos]++) {
    long long i = st[pos];
    long long nx = edge[pos][i].to;
    if (level[nx] != level[pos] + 1) continue;
    if (edge[pos][i].cap == 0) continue;
    long long curflow = maxflow(nx, min(bcap, edge[pos][i].cap));
    if (curflow == 0) continue;
    edge[pos][i].cap -= curflow;
    edge[nx][edge[pos][i].backidx].cap += curflow;
    return curflow;
  }
  return 0;
}
int main() {
  cin >> n >> m;
  memset(dist, INFMEM, sizeof(dist));
  for (int i = 1; i <= m; i++) {
    long long u, v;
    cin >> u >> v;
    dist[u][v] = 1;
  }
  for (int i = 1; i <= n; i++) dist[i][i] = 0;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  cin >> ShipN >> BaseN >> DepM;
  for (int i = 1; i <= ShipN; i++) {
    cin >> ship[i].pos >> ship[i].att >> ship[i].fuel >> ship[i].price;
    events.push_back({ship[i].att, i, 0});
  }
  for (int i = 1; i <= BaseN; i++) {
    cin >> base[i].pos >> base[i].def >> base[i].price;
    events.push_back({base[i].def, i, 1});
  }
  sort(events.begin(), events.end());
  for (int i = 1; i <= n; i++) CurMaxgold[i] = -LINF;
  for (int i = 0; i < events.size(); i++) {
    long long curidx = events[i].idx;
    if (events[i].type == 1) {
      CurMaxgold[base[curidx].pos] =
          max(CurMaxgold[base[curidx].pos], base[curidx].price);
    } else {
      long long u = ship[curidx].pos;
      ship[curidx].profit = -LINF;
      for (int j = 1; j <= n; j++) {
        if (dist[u][j] <= ship[curidx].fuel) {
          ship[curidx].profit =
              max(ship[curidx].profit, CurMaxgold[j] - ship[curidx].price);
        }
      }
    }
  }
  long long ans = 0;
  s = 0;
  e = ShipN + 1;
  for (int i = 1; i <= ShipN; i++) {
    if (ship[i].profit < 0) {
      make_edge(i, e, abs(ship[i].profit), 0);
    } else {
      ans += ship[i].profit;
      make_edge(s, i, ship[i].profit, 0);
    }
  }
  for (int i = 1; i <= DepM; i++) {
    long long u, v;
    cin >> u >> v;
    make_edge(u, v, LINF, 0);
  }
  while (1) {
    memset(level, 0, sizeof(level));
    memset(st, 0, sizeof(st));
    level[s] = 1;
    antri.push({s, 1});
    while (!antri.empty()) {
      dta tmp = antri.front();
      antri.pop();
      bfs(tmp);
    }
    if (level[e] == 0) break;
    long long curflow;
    while (curflow = maxflow(s, LINF)) ans -= curflow;
  }
  printf("%lld\n", ans);
  return 0;
  return 0;
}
