#D7304. Rotate
Rotate
Rotate
Write a program which reads a sequence of integers and rotate specified elements by a list of the following operation:
- rotate(): For each integer (), move element to the place of element .
Constraints
Input
The input is given in the following format.
:
In the first line, (the number of elements in ) is given. In the second line, (each element in ) are given. In the third line, the number of queries is given and each query is given by three integers in the following lines.
Output
Print all elements of in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
Example
Input
11 1 2 3 4 5 6 7 8 9 10 11 1 2 6 9
Output
1 2 7 8 9 3 4 5 6 10 11
inputFormat
Input
The input is given in the following format.
:
In the first line, (the number of elements in ) is given. In the second line, (each element in ) are given. In the third line, the number of queries is given and each query is given by three integers in the following lines.
outputFormat
Output
Print all elements of in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
Example
Input
11 1 2 3 4 5 6 7 8 9 10 11 1 2 6 9
Output
1 2 7 8 9 3 4 5 6 10 11
样例
11
1 2 3 4 5 6 7 8 9 10 11
1
2 6 9
1 2 7 8 9 3 4 5 6 10 11