#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 go(int x,int y) {
	if(x>=h) return 0;
	if(isdigit(g[x][y])) return g[x][y]-'0';
	if(g[x][y]=='*') return (go(x+1,y-1)+go(x+1,y+1))/2;
	return go(x+1,y);
}

void run() {
	scanf("%d%d",&h,&w);
	REP(i,h) REP(j,w) scanf(" %c",&g[i][j]);
	
	double ret=0, v;
	REP(j,w) if((v=go(0,j))>ret) ret=v;
	printf("%.6lf\n",ret);
}

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