var
x,y,s:array[1..2000] of longint;
a:array[1..2000,1..4] of longint;
m,n,k,l,d,i,j,t:longint;
functionmin(x,y:longint):longint;
beginif x<y then min:=x
else min:=y;
end;
begin
readln(m,n,k,l,d);
for i:= 1to d dobeginread(a[i,1],a[i,2],a[i,3],a[i,4]);
if a[i,1]=a[i,3] then
inc(x[min(a[i,2],a[i,4])])
else
inc(y[min(a[i,1],a[i,3])]);
end;
for i:= 1to m doif y[i]>0thenbegin
inc(j);
s[j]:=y[i];
end;
for i:=1to j-1dofor j:=i+1to j doif s[i]<s[j] thenbegin t:=s[i];s[i]:=s[j];s[j]:=t;end;
for i:=1to m doif y[i]>=s[k] thenwrite(i,' ');
writeln;
j:=0;
fillchar(s,sizeof(s),0);
for i:= 1to n doif x[i]>0thenbegin
inc(j);
s[j]:=x[i];
end;
for i:=1to j-1dofor j:=i+1to j doif s[i]<s[j] thenbegin t:=s[i];s[i]:=s[j];s[j]:=t;end;
for i:=1to m doif x[i]>=s[l] thenwrite(i,' ');
end.