#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <complex>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <deque>
#include <bitset>
#include <cctype>
#include <utility>
#include <cassert>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
char a[111][111];
double f[111][111];
int main() {
ios :: sync_with_stdio(false); cin.tie(NULL);
cout << (fixed) << setprecision(6);
int test; cin >> test;
while (test--) {
double res = 0.0;
int m, n; cin >> m >> n;
FOR(i,1,m) FOR(j,1,n) cin >> a[i][j];
FOR(col,1,n) {
double cur = 0.0;
FOR(i,1,m) FOR(j,1,n) f[i][j] = 0.0;
f[1][col] = 1.0;
FOR(i,1,m) FOR(j,1,n)
if (f[i][j] > 1e-9) {
if (a[i][j] >= '1' && a[i][j] <= '9')
cur += f[i][j] * (a[i][j] - '0');
else if (a[i][j] == '*') {
f[i+1][j-1] += f[i][j] / 2.0;
f[i+1][j+1] += f[i][j] / 2.0;
} else f[i+1][j] += f[i][j];
}
res = max(res, cur);
}
cout << (fixed) << setprecision(9) << res << endl;
}
return 0;
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsd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MTExXTsKCmludCBtYWluKCkgewogICAgaW9zIDo6IHN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUoTlVMTCk7CiAgICBjb3V0IDw8IChmaXhlZCkgPDwgc2V0cHJlY2lzaW9uKDYpOwogICAgaW50IHRlc3Q7IGNpbiA+PiB0ZXN0OwogICAgd2hpbGUgKHRlc3QtLSkgewogICAgICAgIGRvdWJsZSByZXMgPSAwLjA7CiAgICAgICAgaW50IG0sIG47IGNpbiA+PiBtID4+IG47CiAgICAgICAgRk9SKGksMSxtKSBGT1IoaiwxLG4pIGNpbiA+PiBhW2ldW2pdOwoKICAgICAgICBGT1IoY29sLDEsbikgewogICAgICAgICAgICBkb3VibGUgY3VyID0gMC4wOwogICAgICAgICAgICBGT1IoaSwxLG0pIEZPUihqLDEsbikgZltpXVtqXSA9IDAuMDsKCiAgICAgICAgICAgIGZbMV1bY29sXSA9IDEuMDsKICAgICAgICAgICAgRk9SKGksMSxtKSBGT1IoaiwxLG4pCiAgICAgICAgICAgICAgICBpZiAoZltpXVtqXSA+IDFlLTkpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoYVtpXVtqXSA+PSAnMScgJiYgYVtpXVtqXSA8PSAnOScpCiAgICAgICAgICAgICAgICAgICAgICAgIGN1ciArPSBmW2ldW2pdICogKGFbaV1bal0gLSAnMCcpOwogICAgICAgICAgICAgICAgICAgIGVsc2UgaWYgKGFbaV1bal0gPT0gJyonKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZbaSsxXVtqLTFdICs9IGZbaV1bal0gLyAyLjA7CiAgICAgICAgICAgICAgICAgICAgICAgIGZbaSsxXVtqKzFdICs9IGZbaV1bal0gLyAyLjA7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGZbaSsxXVtqXSArPSBmW2ldW2pdOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICByZXMgPSBtYXgocmVzLCBjdXIpOwogICAgICAgIH0KCiAgICAgICAgY291dCA8PCAoZml4ZWQpIDw8IHNldHByZWNpc2lvbig5KSA8PCByZXMgPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9Cgo=