var k,mid:real;i,kase:longint; t,now,min,max,a,b,c,l,r:int64; begin readln(t); for kase:=1 to t do begin max:=-maxlongint div 3; min:=maxlongint div 3; readln(a,b,c,l,r); for i:=l to r do begin now:=a*i*i+b*i+c; if nowmax then max:=now; end; writeln(max,' ',min); end; end.