Block Game

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

Input

Output

Sample Input

C
..AB..
..AB..
CCAB..
......
.DDEE.
......
A
......
......
......
......
AA....
......
Z
.ZZ..X
.....X
.....X
.....Y
.....Y
.....Y
*

Sample Output

5
1
-1

Hint

 

Source

2009 Mid-Atlantic Regional Programming Contest