#include<bits/stdc++.h>
using namespace std;
struct node{
int i;
int power;
}heng[1001],shu[1001];
int lenx=0,leny=0;
bool cmp(node a,node b){
if(a.power==b.power) return a.i<b.i;
return a.power>=b.power;
}
bool cmp2(node a,node b){
return a.i<b.i;
}
int main(){
int m,n,k,l,d;
cin>>m>>n>>k>>l>>d;
int a[m][n]={};
for(int i=1;i<=d;i++){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
a[x1-1][y1-1]=i;
a[x2-1][y2-1]=i;
}
for(int i=1;i<=m-2;i++){
int cnt=0;
for(int j=0;j<n;j++){
if(a[i][j]==a[i+1][j]&&a[i][j]!=0&&a[i+1][j]!=0) cnt++;
}
if(cnt){
heng[lenx].i=i;
heng[lenx].power=cnt;
lenx++;
}
}
for(int j=0;j<=n-2;j++){
int cnt=0;
for(int i=0;i<m;i++){
if(a[i][j]==a[i][j+1]&&a[i][j]!=0&&a[i][j+1]!=0) cnt++;
}
if(cnt){
shu[leny].i=j;
shu[leny].power=cnt;
leny++;
}
}
sort(heng,heng+lenx,cmp);
sort(shu,shu+leny,cmp);
sort(heng,heng+k,cmp2);
sort(shu,shu+l,cmp2);
for(int i=0;i<k;i++) cout<<heng[i].i+1<<' ';
cout<<'\n';
for(int i=0;i<l;i++) cout<<shu[i].i+1<<' ';
}