Олимпиадный тренинг

Задача 38872. Sorting


Задача

Темы:
The library has 8 volumes of the complete works of one writer. The librarian marked them with Latin letters from A to H in the order of release of the volumes, but it turned out that they are on the shelf in reverse order:
HGFEDCBA

The librarian decided to rearrange these books so that they are in order: ABCDEFGH. In a one operation, a librarian can take two or more consecutive books, get them from the shelf and, without changing the order of the books, rearrange them to some other place on the shelf (between some other then books, to the beginning or to the end of the shelf).
For example, a librarian might take three FED volumes, remove them from the shelf (leaving the HGCBA volumes on the shelf), and place them so that there are 4 volumes in front of them. You get HGCBFEDA. You can put them at the beginning of the shelf, then you get the sequence FEDHGCBA, and if
put them at the end, you get HGCBAFED.
Help the librarian organize this row of books in the least number of steps.
Write your answer as a sequence of lines, each line must correspond to some arrangement of volumes on the shelf, that is, be a permutation of the characters ABCDEFGH. The first line of the response must be HGFEDCBA, the last line of the response must be ABCDEFGH,
and each line of the answer (except the first) must be obtained from the previous one by applying the specified operation. Please note that a swapped fragment cannot consist of only one book. That is, the answer should look like this (instead of ellipsis, there are several missing lines):
HGFEDCBA
...
...
...
ABCDEFGH
The fewer operations in your algorithm, the more points you get, provided that, as a result of your algorithm, the volumes are arranged in order from A to H.