#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) {
	while(x<h) {
		if(isdigit(g[x][y])) return g[x][y]-'0';
		if(g[x][y]=='*')	if(rand()%2==0) --y; else ++y;
		++x;
	}
	return 0;
}

void run() {
	scanf("%d%d",&h,&w);
	REP(i,h) REP(j,w) scanf(" %c",&g[i][j]);
	
	vector<pair<int,double> > pos; REP(j,w) pos.push_back(make_pair(j,0));
	double ret=-1, v;
	REP(k,10000000) {
		REP(i,pos.size()) {
			pos[i].second+=go(0,pos[i].first);
		}
		if(k%1000==999) {
			ret=0;
			REP(i,pos.size()) if((v=pos[i].second/(k+1))>ret) ret = v;
			int n=0;
			REP(i,pos.size()) if(pos[i].second>ret*(k+1)-100*ret) pos[n++]=pos[i];
			pos.resize(n);
		}
	}
	printf("%.6lf\n",ret);
}

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