program tym;
var f,m,n,k,l,d,i,j,x,y,x1,y1:longint;
    tmp,col,row:array[1..1000] of longint;
    s,s1:ansistring;
function min(a,b:longint):longint;
begin
    if a<b then exit(a); exit(b);
end;
procedure qsort(m,n:Longint);
var ii,jj,mid,t:longint;
begin
    ii:=m; jj:=n; mid:=tmp[(ii+jj)div 2];
    repeat
        while tmp[ii]>mid do inc(ii);
        while tmp[jj]<mid do dec(jj);
        if ii<=jj then begin
            t:=tmp[ii]; tmp[ii]:=tmp[jj]; tmp[jj]:=t;
            inc(ii); dec(jj);
        end;
    until ii>jj;
    if m<jj then qsort(m,jj);
    if ii<n then qsort(ii,n);
end;
begin
    readln(m,n,k,L,d);
    fillchar(row,sizeof(row),0);
    fillchar(col,sizeof(col),0);
    for i:=1 to d do begin
        readln(x,y,x1,y1);
        if x=x1 then inc(col[min(y,y1)]) else inc(row[min(x,x1)]);
    end;
    j:=0;
    for i:=1 to m do begin
        if row[i]>0 then begin
            inc(j);
            tmp[j]:=row[i];
        end;
    end;
    qsort(1,j);
    f:=tmp[k];
    i:=1; j:=0;
    while (i<=n)and(j<k) do begin
        if row[i]>=f then begin
            write(i);
            inc(j);
            if j<>k then write(' ');
        end;
        inc(i);
    end;
    writeln;
    j:=0;
    for i:=1 to n do begin
        if col[i]>0 then begin
            inc(j);
            tmp[j]:=col[i];
        end;
    end;
    qsort(1,j);
    f:=tmp[l];
    i:=1; j:=0;
    while (i<=m) and (j<L) do begin
        if col[i]>=f then begin
            write(i);
            inc(j);
            if j<>l then write(' ');
        end;
        inc(i);
    end;
end.

/**************************************************************
	Problem: 2277
	User: admin
	Language: Pascal
	Result: Wrong Answer
****************************************************************/