var s:string;
a,time,next:array[1..3000]of longint;
i,n,k,id,t,j,min,tt:longint;
procedure qsort(l,r:longint);
var t,i,j,mid,midt:longint;
begin
i:=l; j:=r;
mid:=a[(l+r)div 2];
midt:=time[(l+r)div 2];
while i<j do
begin
while (a[i]<mid) do inc(i);
while (a[j]>mid) do dec(j);
if i<=j then begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
t:=time[i]; time[i]:=time[j]; time[j]:=t;
t:=next[i]; next[i]:=next[j]; next[j]:=t;
inc(i);dec(j);
end;
end;
if l<j then qsort(l,j);
if r>i then qsort(i,r);
end;
begin
while true do begin
readln(s);
if s='#' then break;
inc(i);
delete(s,1,pos(' ',s));
val(copy(s,1,pos(' ',s)-1),ID);
delete(s,1,pos(' ',s));
val(s,t);
a[i]:=ID;
time[i]:=t;
next[i]:=t;
end;
n:=i;
qsort(1,n);
readln(k);
for i:=1 to k do begin
min:=maxlongint;
for j:=1 to n do if next[j]<min then min:=next[j];
for j:=1 to n do if next[j]=min then begin
writeln(a[j]);
next[j]:=next[j]+time[j];
inc(tt);
if tt=k then begin
close(input);
close(output);
halt;
end;
end;
end;
close(input);
close(output);
end.