ALICECUB - Alice’s Cube


Please click here to download a PDF version of the contest problems. The problem is problem A in the PDF.


Alice has received a hypercube toy as her birthday present. This hypercube has 16 vertices, numbered from 1 to 16, as illustrated below. On every vertex, there is a light bulb that can be turned on or off. Initially, eight of the light bulbs are turned on and the other eight are turned off. You are allowed to switch the states of two adjacent light bulbs with different states ("on" to "off", and "off" to "on"; specifically, swap their states) in one operation.

Given the initial state of the lights, your task is to calculate the minimum number of steps needed to achieve the target state, in which the light bulbs on the sub cube (1, 2, 3, 4) - (5, 6, 7, 8) are turned off, and the rest of them are turned on.

Alice's hypercube

Input

There are multiple test cases. The first line of the input contains an integer T, meaning the number of the test cases. There are about 13000 test cases in total.

For each test case there are 16 numbers in a single line, the i-th number is 1 meaning the light of the i-th vertex on the picture is on, and otherwise it’s off.

Output

For every test cases output a number with case number meaning the minimum steps needed to achieve the goal. If the number is larger than 3, you should output "more".

Sample

Input:
3
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1
0 0 0 0 0 0 1 0 1 0 1 1 1 1 1 1

Output:
Case #1: 0
Case #2: 1
Case #3: more

hide comments
Vitalis Salis: 2013-06-11 11:30:37

I can't open the pdf..

Pranjal Successena: 2013-05-08 09:33:07

please explain 3rd case?

brian_calc(2): 2009-11-14 14:03:03

@ Marcin Sasinowski
the final state i.e
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
can be obtained by swapping states of 2 & 10.Also as 2 & 10 are adjacent ,so we get to our final state in 1 move ...

Marcin Sasinowski: 2009-11-13 20:03:11

I don't understand second testcase:
0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1
since 2 and 9 arent adjacent we cannot perform solution with 1 move.
Where is mistake ?


Added by:Fudan University Problem Setters
Date:2009-11-01
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 C99 GOSU NODEJS OBJC PERL6 VB.NET
Resource:ACM/ICPC Regional Contest, Shanghai 2009