Your goal is to find the minimum number of steps to eat all the dots inside an enclosed maze without ghosts.
The possible tiles are listed as follows:
'o': The PacMan on a tile
' ': Nothing on a tile
'.': A dot on a tile
'#': Wall
Your program only needs to deal with valid inputs. It is guaranteed that:
Example 1:
Input:
1
4 9
######### # o...# # . ##### #########
Output:
9
Sequence of steps:
ASAWDDDDD
where:
W
: move the PacMan upA
: move the PacMan leftS
: move the PacMan downD
: move the PacMan rightThe first line contains a single integer T (1 ≤ T ≤ 100). Then T test cases follow.
For each test case:
For each test, output the minimum number of steps to eat all the dots inside the enclosed maze without ghosts.