#include<bits/stdc++.h> using namespace std; const int maxn = 1007; char str[maxn][maxn]; int cntx[maxn], cnty[maxn],x[maxn],y[maxn]; int main(void){ int T,n,m;scanf("%d",&T); while(T --){ scanf("%d%d",&n,&m); int tot = 0; memset(cntx, 0, sizeof(cntx)); memset(cnty, 0, sizeof(cnty)); memset(x, -1, sizeof(x)); memset(y, -1, sizeof(y)); for(int i = 0; i < n; i ++){ scanf("%s", str[i]); for(int j = 0; j < m; j ++){ if(str[i][j] == '#'){ cntx[i] ++;cnty[j] ++; tot ++; }else{ x[i] = j;y[j] = i; } } } long long ans = 0; for(int i = 0; i < n; i ++) for(int j = i + 1; j < n; j ++) ans += (long long)(j - i) * cntx[i] * cntx[j] * 2; for(int i = 0; i < m; i ++) for(int j = i + 1; j < m; j ++) ans += (long long)(j - i) * cnty[i] * cnty[j] * 2; int cnt = 0; for(int i = 0; i < n; i ++){ if(x[i] == -1) cnt = 0; else if(i == 0 || x[i] <= x[i - 1]) cnt = x[i]; else cnt += x[i]; if(x[i] != -1) ans += 4LL * cnt * (m - x[i] - 1); } cnt = 0; for(int i = 0; i < n; i ++){ if((i == 0)||(x[i] > x[i - 1])||(x[i] == -1)) cnt = m - x[i] - 1; else cnt += m - x[i] - 1; if(x[i] >= 0) ans += 4LL * (cnt - m + x[i] + 1) * (x[i]>0?x[i]:0); } cnt = 0; for(int i = 0; i < m; i ++){ if(y[i] == -1) cnt = 0; else if(i == 0 || y[i] <= y[i - 1]) cnt = y[i]; else cnt += y[i]; ans += 4LL * cnt * (n - y[i] - 1); } cnt = 0; for(int i = 0; i < m; i ++){ if((i == 0)||(y[i] > y[i - 1])||(y[i] == -1)) cnt = n - y[i] - 1; else cnt += n - y[i] - 1; if(y[i] >= 0) ans += 4LL * (cnt - n + y[i] + 1) * (y[i]>0?y[i]:0); } printf("%.4lf ",(double)ans/tot/tot); } return 0; }