var
i,j,n,num,x,y,df:longint;
begin
assign(input,'table2.in');
reset(input);
assign(output,'table2.out');
rewrite(output);
read(n);
for i:=1 to n do begin
read(num);
for j:=1 to num do begin
read(x,y);
if sqr(x-30)+sqr(y-30)<400 then df:=df+1;
if sqr(x-100)+sqr(y-30)<100 then df:=df+2;
if sqr(x-170)+sqr(y-30)<25 then df:=df+3;
end;
writeln(df); df:=0;
end;
close(input);
close(output);
end.