Under construction

Still being built. Things may change

Cross Flip

Interview

Time limit1sMemory limit256 MB

Summary
Find the fewest cross-shaped clicks that turn an all-white 3x3 board into each given target pattern.
Level

Easy3 of 10

Topics
Brute force, Simulation
Solved
No attempts yet

Problem

You are given a 3x3 board. Each square starts out white or black. When you click a square, that square and the squares next to it to the north, south, east, and west (the ones that exist on the board) flip color: white becomes black, and black becomes white.

You want to turn an all-white 3x3 board into the board given in the input. You cannot rotate the board.

Input

The first line has the number of test cases PP (0<P≤500 < P \le 50).

Each test case is three lines of three characters. * means black and . means white.

Output

For each test case, print the minimum number of clicks needed to turn the all-white board into the board given in the input, one answer per line.

Examples1

  1. Example 1

    Input
    2
    *..
    **.
    *..
    ***
    *..
    ..*
    
    Expected output
    1
    3