Puzzle
Vasya enjoys solving various puzzles, one of which is depicted in the figure. It features a rectangular box with three identical square cutouts, each aligned with the sides of the box. The cutouts are symmetrically placed, as shown in the figure, creating a simple system of corridors within the box. In these corridors, there are black and white balls, each with a diameter of 1. The corridor width and the side length of each square cutout are also 1. The box dimensions are 7×3, as illustrated in the figure.
The game involves the following action: in one move, you can rotate the balls around any of the cutouts by one position clockwise. The initial arrangement of the balls in the puzzle is provided, and the goal is to reach a specified target arrangement in the fewest possible moves.
Input
The input file begins with the initial state of the puzzle. A white ball is represented by the letter 'w', a black ball by the letter 'b', and a square cutout by a space. Below is an example input corresponding to the figure. After the initial state, there is a blank line, followed by the target state in the same format.
Output
Output the minimum number of moves required to achieve the target arrangement, or -1 if it is impossible to solve the puzzle.