Problem J

Turn the Lights Off

Input: standard input

Output: standard output

Time Limit: 3 seconds

Memory Limit: 32 MB

 

Since we all rely on mother earth, it's our duty to save her. Therefore, you're now asked to save energy by switching lights off.

A friend of yours has the following problem in his job. There's a grid of size 10x10, where each square has a light bulb and a light switch attached to it. Unfortunately, these lights don't work as they are supposed to. Whenever a switch is pressed, not only its own bulb is switched, but also the ones left, right, above and under it. Of course if a bulb is on the edge of the grid, there are fewer bulbs switched.

When a light switches it means it's now on if it was off before and it's now off if it was on before. Look at the following examples, which show only a small part of the whole grid. They show what happens if the middle switch is pressed. "O" stands for a light that's on, "#" stands for a light that's off.

###      #O#
###  ->  OOO
###      #O#
 
###      #O#
OOO  ->  ###
###      #O#

Your friend loves to save energy and asks you to write a program that finds out if it is possible to turn all the lights off and if possible then how many times he has to press switches in order to turn all the lights off.

Input

There are several test cases in the input. Each test case is preceded by a single word that gives a name for the test case. After that name there follow 10 lines, each of which contains a 10-letter string consisting of "#" and "O". The end of the input is reached when the name string is "end".

Output

For every test case, print one line that consists of the test case name, a single space character and the minimum number of times your friend has to press a switch. If it is not possible to switch off all the lights or requires more than 100 presses then the case name should be followed by space and then a -1.

Sample Input

all_off
##########
##########
##########
##########
##########
##########
##########
##########
##########
##########
all_on
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
simple
#O########
OOO#######
#O########
####OO####
###O##O###
####OO####
##########
########O#
#######OOO
########O#
end

 

Sample Output

all_off 0
all_on 44
simple 4

(The Joint Effort Contest, Problem setter: Stefan Pochmann)