program Project8;

{$APPTYPE CONSOLE}

uses
  SysUtils;
type mas=array [1..100,1..100] of integer;
var m,k,i,y,x,n,j,q:integer;
d:real;
a:mas;
begin
assign (input,'traps.in');
reset (input);
read(n);a[1,1]:=0;a[2,1]:=0;
for i:=1 to n do
begin
 read(k);
for j:=2 to (k+1) do
begin
d:=0;
read(x,y);
a[1,j]:=x;
a[2,j]:=y;
end;
for q:=2 to k+1  do
d:=d+sqrt(sqr(a[1,q]-a[1,q-1])+sqr(a[2,q]-a[2,q-1]));
d:=d+sqrt(sqr(a[1,k+1]-a[1,1])+sqr(a[2,k+1]-a[2,1]));
writeln(d:4:2);
end;
end.
