#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)


int h,w;
char g[100][100];

double dp[100][100];

void run() {
	scanf("%d%d",&h,&w);
	REP(i,h) REP(j,w) scanf(" %c",&g[i][j]);
	
	REP(j,w) dp[h-1][j]=isdigit(g[h-1][j])?g[h-1][j]-'0':0;
	for(int i=h-2;i>=0;--i) REP(j,w) dp[i][j]=isdigit(g[i][j])?g[i][j]-'0':g[i][j]=='*'?(dp[i+1][j-1]+dp[i+1][j+1])/2:dp[i+1][j];
	
	double ret=dp[0][0]; FOR(j,1,w) if(dp[0][j]>ret) ret=dp[0][j]; printf("%.6lf\n",ret);
}

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