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