/*
 * TODOEJ: write actual solution.
 *
 * First idea:
 * dp[row][col][cancol][canrow][candiag1][candiag2][balls] which indicates the probability of getting lingo when:
 *   - the current row is 'row'
 *   - the current column is 'col'
 *   - the columns indicated in the mask 'cancol' can still give lingo.
 *   - canrow indicates if the row can still give lingo
 *   - candiag1 indicates if the first diagonal can still give lingo.
 *   - candiag2 indicates if the second diagonal can still give lingo.
 *	 - balls indicates the number of balls left.
 * Rough bound on the complexity of this solution is O(n^2*2^n*2*2*n^2) which is about 40 million for n=10.
 */

#include <cstdio>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)

int n,k;
double dp[2][1<<10][2][2][2][101];

char g[10][10];

void run() {
	scanf("%d%d",&n,&k);
	REP(i,n) REP(j,n) scanf(" %c",&g[i][j]);
	
	int left=0; REP(i,n) REP(j,n) if(g[i][j]=='.') ++left;
	
	int a=0,b=1;
	double ret=0;
	REP(v,1<<n) REP(w,2) REP(x,2) REP(y,2) REPE(z,k) dp[a][v][w][x][y][z]=0; dp[a][(1<<n)-1][1][1][1][k]=1;
	REP(i,n) REP(j,n) {
		a=1-a; b=1-b;
		REP(v,1<<n) REP(w,2) REP(x,2) REP(y,2) REPE(z,k) dp[a][v][w][x][y][z]=0;
		REP(v,1<<n) REP(w,2) REP(x,2) REP(y,2) REPE(z,k) REP(c,2) {
			if(c==0&&g[i][j]=='*') continue;
			int nv=v,nw=w,nx=x,ny=y,nz=z; double np=dp[b][v][w][x][y][z];
			if(c==0) {
				nv&=~(1<<j);
				nw=0;
				if(i==j) nx=0;
				if(i==n-j-1) ny=0;
				if(left>0) np*=1.0*(left-z)/(left);
			} else {
				if(g[i][j]=='.') --nz;
				if(nz<0) continue;
				if(g[i][j]=='.') np*=1.0*z/left;
			}
			if(i==n-1&&(nv&(1<<j))!=0||j==n-1&&nw==1||i==n-1&&j==n-1&&nx==1||i==n-1&&j==0&&ny==1) { ret+=np; continue; }
			if(j==n-1) nw=1;
			dp[a][nv][nw][nx][ny][nz]+=np;			
		}
//		REP(v,1<<n) REP(w,2) REP(x,2) REP(y,2) REPE(z,k) if(dp[a][v][w][x][y][z]>0) printf("%d %d: %d %d %d %d %d: %lf\n",i,j,v,w,x,y,z,dp[a][v][w][x][y][z]);
//		printf("%lf\n",ret);
		if(g[i][j]=='.') --left;
	}
	printf("%.9lf\n",100*ret);
}

int main() {
	int n; scanf("%d",&n); REP(i,n) run();
	return 0;
}
