#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
#include <cassert>
#include <random>
#include <map>
#include <algorithm>

using namespace std;

// solves a system of linear equation by using
// Gaussian elimination.
// It is expected that solution always exists.
vector<double> gauss(vector<vector<double>> A)
{
	int n = A.size();
	int m = A[0].size();
	assert(n + 1 == m);

	for (int i = 0;i < n;i++)
	{
		int maxj = i;
		for (int j = i;j < n;j++)
		{
			if (fabs(A[j][i]) > fabs(A[maxj][i]))
				maxj = j;
		}
		assert(fabs(A[maxj][i]) > 0.0000000000001);
		swap(A[i], A[maxj]);

		double piv = A[i][i];
		for (int k = i + 1;k < n;k++)	// row enumeration
		{
			double coeff = A[k][i] / piv;
			for (int j = i;j < m;j++)	// col enumeration
			{
				double sub = A[i][j]*coeff;
				A[k][j] -= sub;
			}
			A[k][i] = 0;
		}
	}

	// back substitution.
	vector<double> res(n, 0);
	for (int i = n - 1;i >= 0;i--)	// current row
	{
		res[i] = A[i][m-1];
		for (int j = n - 1;j > i;j--)
		{
			res[i] -= res[j]*A[i][j];
		}
		res[i] /= A[i][i];
	}
	return res;
}

void print_perm(vector<int>& perm)
{
	cout <<perm.size() <<endl;
	for (int i = 0;i < perm.size();i++)
		cout <<perm[i] << (i != perm.size() - 1 ? " " : "");
	cout <<endl;
}

void gen_tests()
{
	freopen("game.in", "w", stdout);
	int t = time(NULL);
	srand(t);

	vector<int> perm;
	perm.resize(5, 0);
	for (int i = 0;i < perm.size();i++)
		perm[i] = i + 1;

	vector<vector<int>> perms;
	do
	{
		perms.push_back(perm);
	}
	while (next_permutation(perm.begin(), perm.end()));

	perm.resize(4, 0);
	for (int i = 0;i < perm.size();i++)
		perm[i] = i + 1;
	do
	{
		perms.push_back(perm);
	}
	while (next_permutation(perm.begin(), perm.end()));


	perm.resize(3, 0);
	for (int i = 0;i < perm.size();i++)
		perm[i] = i + 1;
	do
	{
		perms.push_back(perm);
	}
	while (next_permutation(perm.begin(), perm.end()));

	shuffle (perms.begin(), perms.end(), default_random_engine(t));

	cout <<perms.size() <<endl;
	for (int i = 0;i < perms.size();i++)
		print_perm(perms[i]);
}

void main()
{
	//gen_tests();
	//return;

	cout.setf(ios_base::fixed);
	cout.precision(4);

	//ifstream in("input.txt");
	freopen("game.in", "r", stdin);
	//freopen("game.out", "w", stdout);
	int tc;
	cin >>tc;
	for (int cc = 0;cc < tc;cc++)
	{
		int M;
		cin >>M;
		vector<char> V(M);
		for (int i = 0;i < M;i++)
		{
			int x;
			cin >>x;
			V[i] = x - 1;
		}

		map<vector<char>, int> ind;
		vector<char> perm(M);
		for (int i = 0;i < M;i++)
			perm[i] = i;

		int v_cnt = 0;
		do
		{
			ind[perm] = v_cnt++;
		}
		while (next_permutation(perm.begin(), perm.end()));

		vector<vector<double>> A(v_cnt, vector<double>(v_cnt + 1, 0));

		int inc = M*(M-1)/2;			// number of incident vertexes for each vertex.
		double edge_prob = 1.0 / inc;

		for (int i = 0;i < M;i++)
			perm[i] = i;

		int beauty_index = ind[perm];
		A[beauty_index][beauty_index] = 1;

		next_permutation(perm.begin(), perm.end());	// skip beautiful permutation.
		do
		{
			int index = ind[perm];
			for (int i = 0;i < M;i++)
				for (int j = i + 1;j < M;j++)
				{
					vector<char> new_perm = perm;
					swap(new_perm[i], new_perm[j]);

					A[index][index] = 1;
					A[index][ind[new_perm]] = -edge_prob;
					A[index][v_cnt] = 1;
				}
		}
		while (next_permutation(perm.begin(), perm.end()));

		vector<double> r = gauss(A);
		int index = ind[V];
		cout <<r[index] <<endl;
	}
}
