program a2;
var
n,m,i,j,x,y,k:longint;
begin
assign(input,'table2.in');
reset(input);
assign(output,'table2.out');
rewrite(output);
readln(n);
for i:=1 to n do begin
readln(m); k:=0;
for j:=1 to m do begin
read(x,y);
if (10<x)and(x<50)and(y<50)and(10<y)and (sqrt((x-30)*(x-30)+(y-30)*(y-30))<20)then inc(k) else
if (90<x)and(x<110)and(20<y)and(y<40)and(sqrt((x-100)*(x-100)+(y-30)*(y-30))<10)then k:=k+2 else
if (165<x)and(x<175)and(25<y)and(y<35)and(sqrt((x-170)*(x-170)+(y-30)*(y-30))<5)then k:=k+3;
end;
writeln(k);
end;
close(input);
close(output);
end.