using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = a[0], m = a[1], r = a[2], q = a[3];
        long inf = (long)1e16;
        var nodes = new node[n + r + 1];
        var edge = new List<Tp>[n + 1];
        for (int i = 0; i <= n; i++)
        {
            edge[i] = new List<Tp>();
        }
        for (int i = 0; i < m; i++)
        {
            a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            edge[a[1]].Add(new Tp(a[0], a[2]));
        }
        for (int i = 0; i <= n; i++)
        {
            nodes[i] = new node(i, 0, edge[i]);
        }
        var edr = new List<Tp>[r];
        for (int i = 0; i < r; i++)
        {
            edr[i] = new List<Tp>();
            for (int j = i; j <= n; j += r)
            {
                edr[i].Add(new Tp(j, 0));
            }
        }
        for (int i = 0; i < r; i++)
        {
            nodes[i + n + 1] = new node(i + n + 1, 0, edr[i]);
        }
        var costs = new long[r][];
        for (int i = 0; i < r; i++)
        {
            costs[i] = dijk(nodes, i + n + 1);
        }
        long sum = 0;
        for (int i = 0; i < q; i++)
        {
            a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long cost = inf;
            for (int j = 0; j < r; j++)
            {
                cost = Math.Min(cost, costs[j][a[0]] + costs[j][a[1]]);
            }
            if (a[2] > cost)
                sum += a[2] - cost;
        }
        Console.WriteLine(sum);
    }
    public struct Tp
    {
        public int Item1;
        public long Item2;
        public Tp(int a, long b)
        {
            Item1 = a;
            Item2 = b;
        }
    }
    public class node : IComparable<node>
    {
        public int id;
        public long dist;
        public List<Tp> edge;
        public int CompareTo(node x)
        {
            return x.dist.CompareTo(this.dist);
        }
        public node(int id) : this(id, 0, new List<Tp>()) {}
        public node(int id, long dist, List<Tp> edge)
        {
            this.id = id;
            this.dist = dist;
            this.edge = edge;
        }
        public void addedge(int to, long cost)
        {
            edge.Add(new Tp(to, cost));
        }
    }
    public class PQ
    {
        List<node> buf;
        public PQ()
        {
            buf = new List<node>();
        }
        void swap(int i, int j)
        {
            var t = buf[i];
            buf[i] = buf[j];
            buf[j] = t;
        }
        public void push(node e)
        {
            int n = buf.Count;
            buf.Add(e);
            while (n > 0)
            {
                int i = (n - 1) >> 1;
                if (buf[n].CompareTo(buf[i]) > 0)
                    swap(i, n);

                n = i;
            }
        }
        public node pop()
        {
            node ret = buf[0];
            int n = buf.Count - 1;
            buf[0] = buf[n];
            buf.RemoveAt(n);
            for (int i = 0, j; (j = (i << 1) + 1) < n; i = j)
            {
                if (j != n - 1 && buf[j].CompareTo(buf[j + 1]) < 0)
                    ++j;
                if (buf[i].CompareTo(buf[j]) < 0)
                    swap(i, j);
            }
            return ret;
        }
        public int Count {get{return buf.Count;}}
    }
    public static long[] dijk(node[] nodes, int s)
    {
        int n = nodes.Length;
        long[] dist = new long[n];
        var q = new PQ();
        for (int i = 0; i < n; i++)
        {
            dist[i] = (long)1e16;
        }
        dist[s] = 0;
        q.push(nodes[s]);
        while (q.Count > 0)
        {
            var p = q.pop();
            if (p.dist.CompareTo(dist[p.id]) > 0)continue;
            foreach (var i in p.edge)
            {
                var d = dist[p.id] + i.Item2;
                if (dist[i.Item1].CompareTo(d) > 0)
                {
                    dist[i.Item1] = d;
                    q.push(new node(i.Item1, d, nodes[i.Item1].edge));
                }
            }
        }
        return dist;
    }
}

Measured memory_bytes: 57512