type Typ = record token : integer; back : longint; end; var textik : array [1..330000] of Typ; pos, a, l : integer; t : integer; poc : integer; i, ii : integer; max : longint; koniec : longint; begin readln(poc); for ii:=1 to poc do begin readln(l,a); t:=0; pos:=0; koniec:=0; while (a>=0) and (l>=1) do begin inc(t); for i:=1 to l do textik[pos+i].token:=t; pos:=pos+l; if pos + a > koniec then koniec:=pos+a; for i:=1 to a do inc(textik[pos+i].back); readln(l,a); end; t:=textik[1].token; max:=0; i:=1; writeln('Zadani ',ii,':'); while (i<=pos) do begin if textik[i].token = t then begin if textik[i].back > max then max:=textik[i].back; textik[i].back:=0; textik[i].token:=0; inc(i); end else begin t:=textik[i].token; writeln(max); max:=0; end; end; writeln(max); for i:=pos-1 to koniec do begin textik[i].back:=0; textik[i].token:=0; end; writeln; end; end.