368. Black and White. One day over a cup of tea, Professor Rackbrain showed his friends the following old puzzle.

![](https://cdn.mathpix.com/cropped/2024_05_21_56f37ca27ac3d928838dg-119.jpg?height=162&width=902&top_left_y=1501&top_left_x=583)

Arrange 4 white and 4 black chips in a row, alternating as shown in the picture. The puzzle is to move two adjacent chips to one of the ends, then move two other adjacent chips to the vacated space, and so on, until after 4 moves all the chips form a straight line without gaps, with the 4 black chips followed by the 4 white chips. Remember, you can only move adjacent chips.

- Now,- said Rackbrain,-since you have learned how to play this game, try another version. The conditions remain the same, but when moving two adjacent chips, you must swap their positions. For example, if you move chips 5,6 to the end, you must place them in the order 6,5. How many moves will it take now?
368. In the first case, move the pairs in the following order: place 6 and 7 before 1, then 3 and 4, 7 and 1, and 4 and 8 in the free spaces. This will result in the following arrangement of chips: 6,4, 8,2,7,1,5,3.

In the second case, move the chips 3,4 and place them in reverse order (4,3) before chip 1. Then move, simultaneously reversing the order of the chips, the pairs 6,7 (after rearrangement 7,6), 6,5 (after rearrangement 5,6), 3,1 (after rearrangement 1,3), and 6,8 (after rearrangement 8,6). The chips will be arranged in the sequence \(4,8,6,2,7,1,3,5\) in just 5 moves.