Birds are stupendous animals. Many species of them perform different rituals throughout their life; from courtship dances of peacocks to moon walking of red-capped manakins. Among all, we are studying the permutation dance in this problem. This ritual is performed by a group of birds sitting in a row on a wire or tree branch, as shown in the figure.
The ritual can be simplified to a performance based on a sequence of actions of these types:
Given the initial position of the birds in the row and the sequence of actions, your task is to compute the final position of the birds in the ritual.
The input starts with a line containing two space-separated integers () and (). The second line contains space-separated bird names, as the initial configuration of the ritual (positioning of the birds in the row, from left to right). Each bird name is a non-empty string of at most (lowercase) alphanumeric characters ( to , and to ).
The sequence of actions is provided in the next s lines, one action per line. Each line is in one of the following formats based on the action type. The bird-name parameter in the actions has the similar format as the second line of the input.
insert bird-name position
The position
parameter is an integer showing the number of birds to the left of the insertion position. This parameter is in the range where is the total number of birds in the row before the insertion. Position puts the bird in the beginning (leftmost position) of the row, and position puts the bird in the end (rightmost position).
depart bird-name
relocate bird-name displacement
The displacement
parameter is an integer that can be positive, negative, or zero. The bird flies to her own position if the displacement is . Otherwise, the bird flies over k birds on his right (left) if displacement is positive(negative),where is the absolute value of displacement. This parameter is in the range where and are respectively the numbers of birds to the left and to the right of the moving bird in the row before the relocation. Displacement puts the bird in the beginning(left most position) of the row,and displacement puts the bird in the end (right most position).
No two participating birds share the same name.Moreover,it is guaranteed that all the actions are meaningful at the moment of execution and there is always at least one bird on the branch throughout the ritual.
Print a single line in the output containing the final configuration of the ritual. The line should contain the space-separated list of the bird names in the row(from left to the right).
A video of the first two sample inputs is provided in the attachment package. Copyright notice: the images and videos of this problem are taken from the following addresses: