program fl;
var
r,s:array[1..3] of longint;
a,b,c,d,n,h,i,k,j,m,zl:longint;
begin
assign(input,'table2.in');
reset(input);
assign(output,'table2.out');
rewrite(output);
read(n);
for a:=1 to n do
begin
read(h); zl:=0;
for b:=1 to h do
begin
read(i,j);
if ((i-30)*(i-30)+(j-30)*(j-30))<400 then zl:=zl+1;
if ((i-100)*(i-100)+(j-30)*(j-30))<100 then zl:=zl+2;
if ((i-170)*(i-170)+(j-30)*(j-30))<25 then zl:=zl+3;
end;
writeln(zl);
end;
close(input);
close(output);
end.