{
TASK:school
LANG:pascal
}
program asdasd;
var n,m,k,code:integer;
b,g:array [1..10000] of integer;
i,j,c,bb,bg,x,tb,tg:integer;
p:char;
s:string;
begin
readln(n,m,k);
bb:=0;bg:=0;
for i:=1 to n do begin
repeat
read (p);S:=s+p;until p=' ';
s:=copy(s,1,length(s)-1);
val(s,c,code);s:='';
read(p);
if p='B' then begin bb:=bb+1;b[bb]:=c;end
else begin bg:=bg+1;g[bg]:=c;end;if i<>n then read(p);end; readln;
for i:=1 to m do begin
repeat
read (p);S:=s+p;until p=' ';
s:=copy(s,1,length(s)-1);
val(s,c,code);s:='';
read(p);
if p='B' then begin bb:=bb+1;b[bb]:=c;end
else begin bg:=bg+1;g[bg]:=c;end;if i<>m then read(p);end; readln;
for i:=1 to bb do
for j:=i+1 to bb do
if b[i]<b[j] then begin x:=b[i];b[i]:=b[j];b[j]:=x;end;
for i:=1 to bg do
for j:=i+1 to bg do
if g[i]<g[j] then begin x:=g[i];g[i]:=g[j];g[j]:=x;end;
if (bb<k) and (bg>=k) then begin
tb:=b[bb];tg:=g[k+k-bb];
end;
if (bg<k) and (bb>=k) then begin
tg:=g[bg];tb:=b[k+k-bg];
end;
writeln(tb,' ',tg);
{for i:=1 to bb do write(b[i],' '); writeln;
for j:=1 to bg do write(g[bg],' '); writeln;}
readln;
end.