program Exams;
var
d,t,s:array [1..1000000] of integer;
i,n,k,k1,j,a,b,c,x,max,f,h:integer;
procedure swap(a,b: integer);
var u,v: integer;
begin
  u:=a; v:=b;
  a:=v; b:=u;
end;

begin
read(n);
for i:=1 to 2*n do
 if (i mod 2=1) then
   read(t[i div 2 + 1])
 else
   read(d[i div 2]);
   k:=0;
   for k1:=1 to n do if d[i]>t[i] then begin
   swap(d[i] , d[n-k]); swap(t[i],t[n-k]); k:=k+1;end;
   for i:=1 to (k-1) do for j:=1 to (k-1) do if d[j]>d[j+1]
   then begin swap(d[j],d[j+1]); swap(t[j],t[j+1]);end;
   for i:=1 to k do s[i]:=t[i]-d[i];
   max:=s[1]; for f:=2 to k do if s[i]>max then begin
   max:=s[i]; a:=i; end;
   for i:=1 to a do swap(d[a-i+1], d[a-i]);
   b:=0; x:=0; i:=1;
   while (t[a]=x) or (t[a]>x) do
     begin x:= x+d[i]; b:=b+1;i:=i+1;end;
     h:=(b-1);
     write(h);
     end.


