import java.util.Arrays;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
private static Scanner cin;
private static int m;
private static int n;
private static int k;
private static int l;
private static int d;
public static void main(String args[]) throws Exception {
cin = new Scanner(System.in);
String t = cin.nextLine();
String[] v = t.split(" ");
m = Integer.valueOf(v[0]);
n = Integer.valueOf(v[1]);
k = Integer.valueOf(v[2]);
l = Integer.valueOf(v[3]);
d = Integer.valueOf(v[4]);
int x,y,p,q;
TreeMap<Spliter,Integer> tmK = new TreeMap<>();
TreeMap<Spliter,Integer> tmL = new TreeMap<>();
for(int i=0;i<d;i++) {
t = cin.nextLine();
v =