Hop - Don`t Walk#1275

Hop - Don`t Walk

1 second
64 megabytes
Medium

KERMIT THE FROG is a classic video game with simple controls and objectives but requires significant thinking.

You control an animated frog that can walk and hop in both forward and backward directions. The frog stands in a space between an otherwise contiguous line of tiles. Each tile is painted black on one side and white on the other. The frog can walk (forward or backward) over an adjacent tile (in front or behind it).

When the frog walks over a tile, that tile slides into the space where the frog was previously standing. For example, in the figure above, the frog has two tiles behind and three in front. We use the notation BWFBBW to represent this state, where F refers to the space (the frog's position), B is a tile with its black face showing, and W is a tile with its white face showing. The forward direction is from left to right. If the frog walks forward, the resulting situation is BWBFBW. Similar behavior happens when the frog walks backward; the tile behind the frog slides into the frog's previous space. The frog can also hop over tiles. The frog can hop over an adjacent tile, landing on the tile next to it. For example, if the frog hops backward, it would land on the first (left-most) tile, and that tile would jump into the space where the frog was standing. Additionally, the tile flips its side. For example, hopping backward in the figure results in: FWWBBW. You are to write a program that determines the minimum number of moves (walks or hops) required to transform a given tile configuration into a configuration where there are no white tile(s) between any black tiles. The frog can be anywhere. If it cannot be solved in 10 or fewer moves, the answer is -1.

Input

Your program will be tested on one or more test cases. Each test case is specified by a single line that contains a string representing the initial tile arrangement. is a non-empty string, no longer than 100 characters, and consists of the letters "B", "W", and exactly one "F". The last line of the input file contains one or more "-" (minus) characters.

Output

For each test case, print the following line:

k. M

Where k is the test case number (starting from one), and M is the minimum number of moves required to reach a configuration where there are no white tile(s) between any black tiles. The frog can be anywhere. M is -1 if the problem cannot be solved in 10 or fewer moves.

Examples

Example 1

Loading
Loading

Note

There is a blank space before M.