// Arup Guha
// 2/13/2023
// Written as an Exercise for the Traveling Salesman DP Algorithm

import java.util.*;

public class relative {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		for (int loop=0; loop<numCases; loop++) {

			int n = stdin.nextInt();
			double[][] costMat = new double[n][n];

			for (int i=0; i<n; i++)
				for (int j=0; j<n; j++)
					costMat[i][j] = stdin.nextDouble();

			System.out.printf("%.2f\n", solve(costMat));
		}
	}

	public static double solve(double[][] mat) {

		int n = mat.length;

		// dp[i][j] stores min cost of traveling to locations in bitmask i, ending at j.
		double[][] dp = new double[(1 << n)][n];

		for (int i=0; i<dp.length; i++)
			Arrays.fill(dp[i], 1000000000);

		// Initialize matrix with first edge from source to all other places.
		for (int i=0; i<n; i++)
			dp[(1 << i)][i] = mat[0][i];

			// Go through each possible subset...
		for (int i=1; i<dp.length; i++) {

			// Go through each ending location.
			for (int j=0; j<n; j++) {

				// Location j isn't visited yet in bitmask i.
				if ((i & (1 << j)) == 0) continue;

				double best = 1000000000;
				for (int k=0; k<n; k++) {

					// Valid previous last node update best value from subset to k to j.
					if (k != j && (i & (1 << k)) != 0) {
						double cur = dp[i - (1 << j)][k] + mat[k][j];
						if (cur < best)
							best = cur;
					}
				}
				dp[i][j] = Math.min(best, dp[i][j]);
			}
		}

		// We want to visit location 0 last.
		return dp[dp.length-1][0];
	}
}
