#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N = 10000;
int h[N],e[N*N],ne[N*N], w[N*N],idx, ans = -0x3f3f3f3f;
int dist[N],cnt[N];
bool st[N];
int D,P,C,F;
void add(int a,int b,int c){
e[idx] = b, ne[idx] = h[a], w[idx] = c,h[a] = idx++;
}
bool spfa(int x){
memset(dist, 0x3f , sizeof dist);
memset(st, 0 , sizeof st);
memset(cnt, 0 , sizeof cnt);
dist[x] = -D;
queue<int> q;
q.push(x);
st[x] = true;
while(q.size()){
int k = q.front();
q.pop();
for(int i = h[k]; i != -1; i = ne[i]){
int j = e[i];
if(dist[j] > dist[k] + w[i]){
dist[j] = dist[k] + w[i];
cnt[j] = cnt[k] + 1;
if(cnt[j] >= C) return false;
if(!st[j]){
q.push(j);
st[j] = true;
}
}
}
}
return true;
}
int main(){
cin >> D >> P >> C >> F;
memset(h, -1, sizeof h);
while(P--){
int a,b;
cin >> a >> b;
add(a,b,-D);
}
while(F--){
int a,b,c;
cin >> a >> b >> c;
add(a,b,c - D);
}
for (int i = 1; i <= C; i++) {
int t = spfa(i);
if (!t) {
puts("orz");
return 0;
}
for (int j = 1; j <= C; j++) {
ans = max(ans, -dist[j]);
}
}
cout << ans << endl;
return 0;
}