The city of Townsville! This nice city is the home for the power puff girls - Blossom, Bubbles, and Buttercup. To introduce their personality we can sing a song:
Blossom, commander and the leader;
Bubbles, she is the joy and the laughter;
Buttercup, she is the toughest fighter.
These super girls defend Townsville from monsters and supervillains using their superpowers, intelligence. They live in a home in Townsville with the professor who is like their father.
The girls are young now and they don't like to fight the monsters anymore. So, if they are outside their home, they are found shopping. And when they get back home, they simply watch TV shows. It's such a horrible fact that the super-intelligent girls are wasting their time watching TV serials that consist of the rivalries between Wives and their Mother in Laws. And when they use computers they are usually found using the face note (a dangerous1 social networking site).
So, such wonderful girls just became lazy and useless. Often they are seen fighting each other, the comments that can be heard, are like, 'Tulsi is the best.', 'Gopi is better than Rashee.' The professor is quite upset with the girls, and he can't even watch any science show or sports because of these irritating serials.
So, the professor made a plan and asked the girls to go shopping such that he can watch an important science show on the TV. The girls became very excited and they went out shopping. But soon they realize that one of their favorite serials will start soon, and they need to get back home for that serial.
To be more specific let's consider the city as a 2D grid. In the grid there are some symbols, the meaning of them are:
.
means an empty place.a
denotes the position of Blossom.b
denotes the position of Bubbles.c
denotes the position of Buttercup.m
denotes that there is a monster.h
denotes their home.#
denotes a wall and the girls cannot pass through it.
The three girls move simultaneously. And in each minute, from their current cells, they can move to any four adjacent cells (North, East, West, South) if the destination cell is neither a wall nor the cell contains a monster. Because they want to get home as soon as possible, they want to avoid the monsters. You can assume that they can move to a common cell if necessary.
Now you are given the information about the city and their positions. You have to find the minimum time when they all are at home.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing two integers: m and n (4 ≤ m, n ≤ 20), m denotes the number of rows and n denotes the number of columns of the modeled grid. Each of the next m lines contains n characters representing the city.
You can assume that a
, b
, c
, h
will occur exactly once in the grid. The outer boundaries will always be marked by #
.
Output
For each case, print the case number and the minimum time needed when they all are in their home. You can assume that a solution will always exist.
Sample
Sample Input | Sample Output |
---|---|
2 6 8 ######## #...c..# #......# #.a.h.b# #......# ######## 5 9 ######### #mmm...c# #ma.h#### #m....b.# ######### | Case 1: 2 Case 2: 4 |