var
p,s,n,i,j,k,x,y:integer;
f,g:text;
begin
assign(f,'table2.in');
assign(g,'table2.out');
reset(f);
rewrite(g);
readln(f,s);
for i:=1 to s do
begin
readln(f,n);
p:=0;
for j:=1 to n do
begin
readln(f,x,y);
if sqr(x-30) +sqr(y-30)<400 then p:=p+1;
if sqr(x-100)+sqr(y-30)<100 then p:=p+2;
if sqr(x-170)+sqr(y-30)<25 then p:=p+3;
end;
writeln(g,p);
end;
close(f);
close(g);
end.