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