/*
  [BAPC'07] PACHINKO
  by: Jan Kuipers
*/

using namespace std;

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

int main () {
  int runs;
  cin>>runs;
  while (runs--) {
    int Y,X;
    cin>>Y>>X;
    vector<string> m(Y);
    for (int y=0; y<Y; y++) cin>>m[y];

    vector<vector<double> > win(Y+1, vector<double>(X, 0));

    for (int y=Y-1; y>=0; y--)
      for (int x=0; x<X; x++) {
	if (isdigit(m[y][x]))
	  win[y][x] = m[y][x]-'0';
	else if (m[y][x]=='.')
	  win[y][x] = win[y+1][x];
	else
	  win[y][x] = (win[y+1][x-1] + win[y+1][x+1])/2;	  
      }

    double res=0,v;
    for (int x=0; x<X; x++) if((v=win[0][x])>res) res=v;
    cout<<setprecision(20)<<res<<endl;
  }
  return 0;   
}
