package 每日一题;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class NC16618 {
    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int N = sc.nextInt();
        int K = sc.nextInt();
        int L = sc.nextInt();
        int D = sc.nextInt();
        int []hang = new int[M+1];
        int []lie = new int[N+1];
        int []hangResult = new int[K];
        int []lieResult = new int[L];
        int o = 0;
        int p = 0;
        for(int i = 0 ;i<D;i++){
            int a1 = sc.nextInt();
            int a2 = sc.nextInt();
            int a3 = sc.nextInt();
            int a4 = sc.nextInt();
            if(judge(a1, a3)){
                lie[Math.min(a2, a4)]++;
            }else{
                hang[Math.min(a1, a3)]++;
            }
        }
        for(int z = 0;z<K;z++){
            int max1 = 0;
            int mark1 = 0;
            for(int k = 1;k<=M;k++){
                if(hang[k]>max1){
                    max1 = hang[k];
                    mark1 = k;
                }
        }
            hangResult[o]=mark1;
            o++;
            hang[mark1]=0;
    }
        
        System.out.println();
        for(int h = 0;h<L;h++){
            int max1 = 0;
            int mark1 = 0;
            for(int j = 1;j<=N;j++){
                if(lie[j]>max1){
                    max1 = lie[j];
                    mark1 = j;
                }
            }
            lieResult[p]=mark1;
            p++;
            lie[mark1]=0;
        
    }
    Arrays.sort(hangResult);
    Arrays.sort(lieResult);
    for(int i = 0;i<K;i++)  System.out.print(hangResult[i]);
    System.out.println();
    for(int i = 0;i<L;i++)  System.out.print(lieResult[i]+" ");
    }

    public static boolean judge(int a1,int a3){
        if(a1==a3)    return true;//说明在同一行
        return false;
    }
}

这题比较简单,能暴力出来。