#include <cstdio>
#include <vector>
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)

typedef long long ll;

int bc[1<<8];
ll choose[65][65];

int n,k;
char g[8][8];

int mark[8][8];

void run() {
	scanf("%d%d",&n,&k);
	REP(i,n) REP(j,n) scanf(" %c",&g[i][j]);
	
	int empty=0; REP(i,n) REP(j,n) if(g[i][j]=='.') ++empty;
	
	ll ways=0;
	memset(mark,-1,sizeof(mark)); int curmark=0;
	REP(rows,1<<n) REP(cols,1<<n) REP(diag1,2) REP(diag2,2) {
		int bits=bc[rows]+bc[cols]+bc[diag1]+bc[diag2];
		if(bits==0) continue;

		int need=0;
		REP(i,n) if(rows&(1<<i)) REP(j,n) if(g[i][j]!='*'&&mark[i][j]!=curmark) mark[i][j]=curmark,++need;
		REP(j,n) if(cols&(1<<j)) REP(i,n) if(g[i][j]!='*'&&mark[i][j]!=curmark) mark[i][j]=curmark,++need;
		if(diag1) REP(i,n) if(g[i][i]!='*'&&mark[i][i]!=curmark) mark[i][i]=curmark,++need;
		if(diag2) REP(i,n) if(g[i][n-i-1]!='*'&&mark[i][n-i-1]!=curmark) mark[i][n-i-1]=curmark,++need;
			
		if(need<=k) ways+=(bits%2==1?+1:-1)*choose[empty-need][k-need];
		
		++curmark;
	}
	
	printf("%.9lf\n",100.0*ways/choose[empty][k]);
}

int main() {
	bc[0]=0; FOR(i,1,1<<8) bc[i]=bc[i>>1]+(i&1);
	REPE(i,64) { choose[i][0]=choose[i][i]=1; FOR(j,1,i) choose[i][j]=choose[i-1][j-1]+choose[i-1][j]; }
	int n; scanf("%d",&n); REP(i,n) run();
	return 0;
}
