#P10997. [2016杭电多校]Game

[2016杭电多校]Game

Game

Problem Description

Sea5 and wzh are playing games. There are some guards on an n × m chessboard. Every guard can attack eight cells around him and release shockwave to attack the whole row and column where he stand. Sea5 and wzh are at the beginning stage of the game, they have already put some guards on the chess cells. No guards can be attacked by another guard right now. So they all fell asleep. An innocent passer-by is on the chessboard. He can move to up, down, left or right from where he stands. The guards won’t attack him unless the passer-by move to where they stand. The innocent man may appear at any point on the chessboard and move to any point. The innocent passer-by wants to know the average shortest distance of all the ways he can move without attacked by guards.

Input

Multiple test cases. The first line is an integer T(T50)T (T \leq 50), the number of cases. For each case, first line is two integers nn and m(2n,m,1000)m (2 \leq n, m, \leq 1000). The next nn lines contain mm symbols indicate the cells of chessboard. ‘G’ indicates a guard and ‘#’ indicates an empty cell.

Output

One line per case, shortest distance of all the ways the passer-by can move without attacked by guards. Round the answer to four decimals.

Sample Input

1
2 2
##
G#

Sample Output

0.8889

Hint

Ways of distance 0: 3 Ways of distance 1: 4 Ways of distance 2: 2 The answer is (3 * 0 + 1 * 4 + 2 * 2) / (3 + 4 + 2)

Author

HIT

Source

2016 Multi-University Training Contest 1