#include <stdlib.h> /* exit */
#include <string.h> /* strcmp, memset */
#include <stdio.h> /* fprintf, fputc, fgets */
#include <limits.h> /* INT_MAX ... */
#include <ctype.h> /* isspace, isalpha, isupper, islower, isdigit */
#include <set>
#include <queue>
#include <string>
using namespace std;

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) < (b) ? (b) : (a))

int board[100][100];
double prob[100][100];

int run ()
{
	int i,j,w,h,k;
	memset(board,0,sizeof(board));
	scanf("%d %d\n",&h,&w);
	char buff[105];
	double bestwin =0.0,curwin;
	for(i=0;i<h;i++)
	{
		scanf("%s\n",buff);
		//printf("%s\n",buff);
		for(j=0;j<w;j++)
		{
			if(buff[j]=='*') board[i][j]=-1;
			if(buff[j]>='1'&&buff[j]<='9') board[i][j]=buff[j]-'0';
		}
	}
	
	/*for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			printf("%d",board[i][j]);
		}
		printf("\n");
	}*/
	
	for(k=0;k<w;k++)
	{
		memset(prob,0,sizeof(prob));
		if(board[0][k]==-1) continue;
		curwin=0.0;
		prob[0][k]=1.0;
		for(i=0;i<h;i++)
		{
			for(j=0;j<w;j++)
			{
				if(board[i][j]>0) curwin+=prob[i][j]* (double) board[i][j];
				if(i<h-1)
				{
					if(board[i][j]<=0)
					{
						if(board[i+1][j]>-1) prob[i+1][j]+=prob[i][j];
						if(board[i+1][j]==-1)
						{
							prob[i+1][j-1]+=0.5*prob[i][j];
							prob[i+1][j+1]+=0.5*prob[i][j];
						}
					}
				}
			}
		}
		
		if(curwin>bestwin) 
		{	
			bestwin=curwin;
			/*printf("%d:\n",k);
			for(i=0;i<h;i++)
			{
				for(j=0;j<w;j++)
				{
					printf("%8.3ld",prob[i][j]);
				}
				printf("\n");
			}*/
		}
	}	
	
	printf("%.12lf\n",bestwin);
	
	return 0;
}

int main ()
{
    int i,T;
    
    scanf("%d\n",&T);
    
    for(i=0;i<T;i++)
    {
    	run();
    } 
    
        
    exit (0);
}
