// Arup Guha
// 3/23/2016
// Solution to 2015 December Bronze USACO Contest Problem: Contaminated Milk(badmilk)

import java.util.*;
import java.io.*;

public class badmilk {

	public static void main(String[] args) throws Exception {

        // Read in intervals.
		BufferedReader stdin = new BufferedReader(new FileReader("badmilk.in"));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
        int n = Integer.parseInt(tok.nextToken());
        int m = Integer.parseInt(tok.nextToken());
        int d = Integer.parseInt(tok.nextToken());
        int s = Integer.parseInt(tok.nextToken());

        event[] all = new event[d+s];
        for (int i=0; i<d; i++) {
            tok = new StringTokenizer(stdin.readLine());
            int person = Integer.parseInt(tok.nextToken())-1;
            int milk = Integer.parseInt(tok.nextToken())-1;
            int t = Integer.parseInt(tok.nextToken());
            all[i] = new event(person, milk, t);
        }

        // Milk = -1 means person got sick.
        for (int i=0; i<s; i++) {
            tok = new StringTokenizer(stdin.readLine());
            int person = Integer.parseInt(tok.nextToken())-1;
            int t = Integer.parseInt(tok.nextToken());
            all[i+d] = new event(person, -1, t);
        }

        // Put in time order.
        Arrays.sort(all);

        // Easy bookkeepping for small data.
        boolean[][] drank = new boolean[n][m];
        boolean[] possible = new boolean[m];
        Arrays.fill(possible, true);

        // Go through events in time order.
        for (int i=0; i<all.length; i++) {

            // A sick event - limit possible bad milks.
            if (all[i].milk == -1) {
                for (int j=0; j<m; j++)
                    possible[j] = possible[j] && drank[all[i].ID][j];
            }

            // Mark this drinking.
            else
                drank[all[i].ID][all[i].milk] = true;
        }

        // Find most.
        int res = 0;
        for (int i=0; i<m; i++) {

            // Only look at the possibly bad milks.
            if (possible[i]) {

                // Now count how many cows drank this.
                int cnt = 0;
                for (int j=0; j<n; j++)
                    if (drank[j][i])
                        cnt++;

                res = Math.max(res, cnt);
            }
        }

		// Write the output.
		FileWriter fout = new FileWriter(new File("badmilk.out"));
        fout.write(res+"\n");
		fout.close();
	}
}

class event implements Comparable<event> {

    public int ID;
    public int milk;
    public int t;

    public event(int who, int what, int myt) {
        ID = who;
        milk = what;
        t = myt;
    }

    // Makes sure sick events come before drinking events of the same time.
    public int compareTo(event other) {
        if (this.t != other.t)
            return this.t - other.t;
        return this.milk - other.milk;
    }

    public String toString() {
        return ID+","+milk+","+t;
    }
}
