#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600123456
typedef pair<long,int> P;

int main(){
  int n,m,r,q;
  cin>>n>>m>>r>>q;

  vector<int> a(m),b(m),c(m);
  rep(i,m) cin>>a[i]>>b[i]>>c[i];
  rep(i,m) a[i]--,b[i]--;

  vector<vector<P>> rev(n);
  rep(i,m) rev[b[i]].pb(mp(c[i], a[i]));

  vector<vector<long>> vec(n,vector<long>(r, INF));

  rep(i,r){
    priority_queue<P, vector<P>, greater<P>> pq;
    for(int j=i; j<n; j+=r){
      vec[j][i] = 0;
      pq.push(mp(0,j));
    }
    while(!pq.empty()){
      auto p = pq.top(); pq.pop();
      long cost = p.fi;
      int v = p.se;
      if(vec[v][i] < cost) continue;
      for(auto to : rev[v]){
        long ncost = cost + to.fi;
        int nv = to.se;
        if(vec[nv][i] > ncost){
          vec[nv][i] = ncost;
          pq.push(mp(ncost, nv));
        }
      }
    }
  }
//rep(i,n) dbg(vec[i]);
  long ans = 0;
  rep(_,q){
    int x,y,z;
    cin>>x>>y>>z;
    x--;y--;
    long get = 0;
    rep(i,r){
      long cost = vec[x][i] + vec[y][i];
      get = max(get, z-cost);
    }
    ans += get;
  }

  cout << ans << endl;

  return 0;
}