#include <bits/stdtr1c++.h>

using namespace std;

typedef long double ld;
typedef complex<ld> pt;

//dp[i][j] := two tours starting from 0, currently at i, another at j.
//dp[i][j] = { del = min(i,j)-1, min( dp[del][j] + d(del,i), dp[i][del] + d(del, j) }
bool comp_x(const pt& l, const pt& r) {
	return l.real() < r.real();
}

ld memo[550][550];
pt p[550];

ld dist(int i, int j) {
	return abs(p[i]-p[j]);
}

ld dp(int i, int j) {
	if (i == 0 || j == 0) return dist(max(i,j), 0);
	if (memo[i][j] >= 0) return memo[i][j];
	int del = min(i,j)-1;
	memo[i][j] = min(dp(del, j) + dist(del, i), dp(i, del) + dist(del, j));
	return memo[i][j];
}


int main() {
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		for (int i = 0; i < n; i++) {
			ld x, y; cin >> x >> y;
			p[i] = pt(x,y);
		}
		sort(p, p+n, comp_x);
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				memo[i][j] = -1;
			}
		}
		cout << fixed << setprecision(15) << dp(n-1,n-1) << endl;
	}
	return 0;
}