#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct Line {
int tag, cnt, idx;
Line() {}
Line(int _tag, int _cnt, int _idx) {
tag = _tag; cnt = _cnt; idx = _idx;
}
bool operator < (const Line & line) const {
return cnt > line.cnt;
}
}Line;
const int maxn = 1005;
Line pass[maxn * 2];
int M, N, K, L, D;
int x, y, p, q;
int ansl[maxn], ansk[maxn];
int main() {
scanf("%d%d%d%d%d", &M, &N, &K, &L, &D);
for (int i = 1; i <= D; i++) {
scanf("%d%d%d%d", &x, &y, &p, &q);
if (x == p) {
int t = min(y, q);
ansl[t] = ansl[t] + 1;
} else {
int t = min(x, p);
ansk[t] = ansk[t] + 1;
}
}
int tot = 0, l = 0, k = 0;
for (int i = 1; i <= M; i++) {
pass[tot++] = Line(0, ansk[i], i);
}
for (int i = 1; i <= N; i++) {
pass[tot++] = Line(1, ansl[i], i);
}
sort(pass, pass + tot);
for (int i = 0; i < tot; i++) {
if (pass[i].tag == 0 && K > 0) {
K = K - 1;
ansk[k++] = pass[i].idx;
} else if (pass[i].tag == 1 && L > 0) {
L = L - 1;
ansl[l++] = pass[i].idx;
}
}
sort(ansk, ansk + k);
sort(ansl, ansl + l);
for (int i = 0; i < k; i++) {
printf("%d%c", ansk[i], i == k - 1 ? '\n' : ' ');
}
for (int i = 0; i < l; i++) {
printf("%d%c", ansl[i], i == l - 1 ? '\n' : ' ');
}
return 0;
}