var
t,n,i,s,j,x,y:longint;
function one(a,b:longint):boolean;
begin
if trunc(sqrt((a-30)*(a-30)+(b-30)*(b-30))+1)<=20 then exit(true) else exit(false);
end;
function two(a1,b1:longint):boolean;
begin
if trunc(sqrt((a1-100)*(a1-100)+(b1-30)*(b1-30))+1)<=10 then exit(true) else exit(false);
end;
function three(a2,b2:longint):boolean;
begin
if trunc(sqrt((a2-170)*(a2-170)+(b2-30)*(b2-30))+1)<=5 then exit(true) else exit(false);
end;
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
readln(x,y);
if one(x,y) then inc(s)
else if two(x,y) then inc(s,2)
else if three(x,y) then inc(s,3);
end;
writeln(s);
end;
close(input);close(output);
end.