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