#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int m, n, k, l, d;
struct node{
int x, y, p, q;
}st[2010];
struct nod{
int c, in;
};
nod kc[1001], lc[1001];
bool cmp(nod a, nod b){
return a.c > b.c;
}
int main(){
cin >> m >> n >> k >> l >> d;
for (int i = 0; i < d; i++){
cin >> st[i].x >> st[i].y >> st[i].p >> st[i].q;
st[i].x--, st[i].y--;
st[i].p--, st[i].q--;
if(st[i].x == st[i].p){
lc[min(st[i].y, st[i].q)].c++;
} else {
kc[min(st[i].x, st[i].p)].c++;
}
}
for (int i = 0; i < m - 1; i++){
kc[i].in = i;
}
for (int i = 0; i < n - 1; i++){
lc[i].in = i;
}
sort(kc, kc + m - 1, cmp);
sort(lc, lc + n - 1, cmp);
for (int i = 0; i < k; i++){
cout << kc[i].in + 1 << ' ';
}
cout << endl;
for (int i = 0; i < l; i++){
cout << lc[i].in + 1 << ' ';
}
return 0;
}