//用go写要一百多行,真的合理吗,而且谁标的简单的?哪里简单了,读题都得读一整子吧
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type Pair struct {
	idx int
	cnt int
}

func main() {
	in := bufio.NewReader(os.Stdin)

	var n, m, k, l, d int
	fmt.Fscan(in, &n, &m, &k, &l, &d)

	// rowCnt[r] 表示第 r 行与 r+1 行之间这条“行缝”能隔开多少对(r=1..n-1)
	// colCnt[c] 表示第 c 列与 c+1 列之间这条“列缝”能隔开多少对(c=1..m-1)
	rowCnt := make([]int, n) // 下标用 1..n-1
	colCnt := make([]int, m) // 下标用 1..m-1

	for i := 0; i < d; i++ {
		var x, y, p, q int
		fmt.Fscan(in, &x, &y, &p, &q)

		if x == p {
			// 同一行 => 左右相邻 => 影响某条列缝
			c := y
			if q < y {
				c = q
			}
			colCnt[c]++
		} else {
			// 同一列 => 上下相邻 => 影响某条行缝
			r := x
			if p < x {
				r = p
			}
			rowCnt[r]++
		}
	}

	// 1) 把每条缝变成 (idx, cnt) 的列表
	rows := make([]Pair, 0, n-1)
	for r := 1; r <= n-1; r++ {
		rows = append(rows, Pair{idx: r, cnt: rowCnt[r]})
	}
	cols := make([]Pair, 0, m-1)
	for c := 1; c <= m-1; c++ {
		cols = append(cols, Pair{idx: c, cnt: colCnt[c]})
	}

	// 2) 按贡献降序排序(贡献相同时按 idx 升序,写得更稳)
	sort.Slice(rows, func(i, j int) bool {
		if rows[i].cnt != rows[j].cnt {
			return rows[i].cnt > rows[j].cnt
		}
		return rows[i].idx < rows[j].idx
	})
	sort.Slice(cols, func(i, j int) bool {
		if cols[i].cnt != cols[j].cnt {
			return cols[i].cnt > cols[j].cnt
		}
		return cols[i].idx < cols[j].idx
	})

	// 3) 取前 k / l 条缝的 idx
	ansRows := make([]int, 0, k)
	for i := 0; i < k; i++ {
		ansRows = append(ansRows, rows[i].idx)
	}
	ansCols := make([]int, 0, l)
	for i := 0; i < l; i++ {
		ansCols = append(ansCols, cols[i].idx)
	}

	// 4) 输出要求升序
	sort.Ints(ansRows)
	sort.Ints(ansCols)

	// 输出
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	for i := 0; i < len(ansRows); i++ {
		if i > 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, ansRows[i])
	}
	fmt.Fprintln(out)

	for i := 0; i < len(ansCols); i++ {
		if i > 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, ansCols[i])
	}
	fmt.Fprintln(out)
}