Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and rotate specified elements by a list of the following operation:

* rotate($b, m, e$): For each integer $k$ ($0 \leq k < (e - b)$), move element $b + k$ to the place of element $b + ((k + (e - m)) \mod (e - b))$.

Constraints

* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
* $1 \leq q \leq 1,000$
* $0 \leq b_i \leq m_i < e_i \leq n$

Input

The input is given in the following format.


$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; m_1 \; e_1$
$b_2 \; m_2 \; e_2$
:
$b_{q} \; m_{q} \; e_{q}$


In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; m_i \; e_i$ in the following $q$ lines.

Output

Print all elements of $A$ 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

Source: aizu | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
input()
a = list(map(int, input().split()))
for _ in range(int(input())):
	(b, m, e) = map(int, input().split())
	x = a[m:e]
	a[b + e - m:e] = a[b:m]
	a[b:b + e - m] = x
print(' '.join(list(map(str, a))))


from collections import deque
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	(b, m, e) = map(int, input().split())
	s = deque(a[b:e])
	s.rotate(e - m)
	a = a[:b] + list(s) + a[e:]
print(*a)


def partial_rotate(origin, begin, middle, end):
	list1 = origin[:begin]
	list2 = origin[begin:end]
	list3 = origin[end:]
	list2_sub1 = list2[middle - begin:]
	list2_sub2 = list2[:middle - begin]
	return list1 + list2_sub1 + list2_sub2 + list3
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
	(b, m, e) = map(int, input().split())
	A = partial_rotate(A, b, m, e)
print(' '.join(map(str, A)))


from sys import stdin
from collections import deque
n = int(stdin.readline())
l = list(map(int, stdin.readline().split()))
q = int(stdin.readline())
for i in range(q):
	inp_l = list(map(int, stdin.readline().split()))
	a = deque(l[inp_l[0]:inp_l[2]])
	a.rotate(inp_l[2] - inp_l[1])
	a = list(a)
	l = l[:inp_l[0]] + a + l[inp_l[2]:]
l = map(str, l)
print(' '.join(l))


n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	(b, m, e) = map(int, input().split())
	s = a[b:e]
	a = a[:b] + s[m - b:] + s[:m - b] + a[e:]
print(*a)


n = int(input())
a = list(map(int, input().split()))
m = int(input())
for i in range(m):
	(b, m, e) = map(int, input().split())
	s = a[b:e]
	a = a[:b] + s[m - b:] + s[:m - b] + a[e:]
print(*a)


def rotate(A, b, m, e):
	B = A[b:e]
	for k in range(e - b):
		A[b + (k + e - m) % (e - b)] = B[k]
	return A
n = int(input())
A = list(map(int, input().split()))
q = int(input())
for i in range(q):
	query = list(map(int, input().split()))
	A = rotate(A, query[0], query[1], query[2])
print(' '.join(map(str, A)))


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for _ in range(Q):
	(b, m, e) = map(int, input().split())
	A = A[:b] + A[e - (e - m) % (e - b):e] + A[b:e - (e - m) % (e - b)] + A[e:]
print(*A)


n = int(input())
A = list(map(int, input().split()))
q = int(input())
for _ in range(q):
	(b, m, e) = map(int, input().split())
	list_rotate = [None] * (e - b)
	for k in range(e - b):
		index = (k + (e - m)) % (e - b)
		list_rotate[index] = A[b + k]
	A = A[:b] + list_rotate + A[e:]
print(*A)


def rotate(li, b, m, e):
	m = m - b
	return li[:b] + li[b + m:e] + li[b:b + m] + li[e:]

def run():
	n = int(input())
	li = input().split()
	assert n == len(li)
	q = int(input())
	for _ in range(q):
		(b, m, e) = [int(x) for x in input().split()]
		li = rotate(li, b, m, e)
	print(' '.join(li))
run()


def main():
	n = int(input())
	org = [int(a) for a in input().split(' ')]
	q = int(input())
	for _ in range(q):
		(b, m, e) = map(int, input().split(' '))
		dummy = org[:]
		for k in range(e - b):
			first = b + k
			second = b + (k + (e - m)) % (e - b)
			dummy[second] = org[first]
		org = dummy[:]
	print(*dummy)
main()


from collections import deque
n = int(input())
a = list(map(int, input().split()))
q = int(input())
cnt = 0
while q:
	q -= 1
	(l, m, r) = map(int, input().split())
	tmp = deque(a[l:r])
	tmp.rotate(r - m)
	a[l:r] = tmp
print(*a)


num_a = int(input())
a = list(map(lambda x: int(x), input().split()))
num_query = int(input())
for _ in range(num_query):
	(begin, margin, end) = map(lambda x: int(x), input().split())
	diff = end - margin
	modulo = end - begin
	a_sliced = a[begin:end]
	a_sliced = [a_sliced[(idx + len(a_sliced) - diff) % modulo] for idx in range(len(a_sliced))]
	a[begin:end] = a_sliced
print(' '.join([str(elem) for elem in a]))


n = input()
l = list(map(int, input().split()))
n = int(input())
for i in range(n):
	(b, m, e) = map(int, input().split())
	l1 = l[b:e]
	l1 = l1[m - e:] + l1[:m - e]
	l[b:e] = l1
l = map(str, l)
print(' '.join(map(str, l)))


_ = int(input())
A = [int(x) for x in input().split()]
q = int(input())
for _ in range(q):
	(b, m, e) = [int(x) for x in input().split()]
	B = A[:]
	for k in range(e - b):
		A[b + (k + e - m) % (e - b)] = B[b + k]
print(*A)


import copy
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
	(b, m, e) = map(int, input().split())
	tmp = a[b:e]
	tmp2 = copy.deepcopy(tmp)
	for k in range(e - b):
		a[b + k] = tmp2[k - (e - m)]
print(*a)


from collections import deque
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	(b, m, e) = map(int, input().split())
	s = a[b:e]
	a = a[:b] + s[m - b:] + s[:m - b] + a[e:]
print(*a)


import copy
n = int(input())
num = list(map(int, input().split()))
tmp = copy.deepcopy(num)
q = int(input())
for _ in range(q):
	(b, m, e) = map(int, input().split())
	for i in range(e - b):
		pos = b + (i + e - m) % (e - b)
		tmp[pos] = num[i + b]
	num = copy.deepcopy(tmp)
print(' '.join((str(n) for n in num)))


_ = input()
A = [int(a) for a in input().split()]
for _ in range(int(input())):
	(b, m, e) = map(int, input().split())
	t = [0] * (e - b)
	for i in range(e - b):
		j = (i + (e - m)) % (e - b)
		t[j] = A[b + i]
	A = A[:b] + t + A[e:]
print(*A, sep=' ')


n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	(b, m, e) = map(int, input().split())
	a = a[:b] + a[m:e] + a[b:m] + a[e:]
print(*a)


from collections import deque
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	(b, m, e) = map(int, input().split())
	s = a[b:e]
	a = a[:b] + s[m - b:] + s[:m - b] + a[e:]
print(*a)


def main():
	n = int(input())
	A = list(map(int, input().split()))
	m = int(input())
	for _ in range(m):
		(a, b, c) = map(int, input().split())
		A[a:c] = A[b:c] + A[a:b]
	print(' '.join(map(str, A)))
main()


n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	(b, m, e) = map(int, input().split())
	tmp = a[b:e]
	a = a[:b] + tmp[m - b:] + tmp[:m - b] + a[e:]
print(*a)


from collections import deque
import sys
input = sys.stdin.readline

def main():
	n1 = int(input())
	l1 = list(map(int, input().split()))
	l2 = []
	for i in range(int(input())):
		(b, m, e) = map(int, input().split())
		for k in range(b):
			l2.append(l1[k])
		for k in range(m, e):
			l2.append(l1[k])
		for k in range(b, m):
			l2.append(l1[k])
		for k in range(e, len(l1)):
			l2.append(l1[k])
		l1 = l2
		l2 = []
	print(' '.join(map(str, l1)))
main()


def solve():
	from sys import stdin
	f_i = stdin
	n = int(f_i.readline())
	A = f_i.readline().split()
	q = int(f_i.readline())
	for i in range(q):
		(b, m, e) = map(int, f_i.readline().split())
		x = A[b:m]
		y = A[m:e]
		A = A[:b] + y + x + A[e:]
	print(' '.join(A))
solve()


import copy
n = int(input())
A = list(map(int, input().split()))
q = int(input())
for i in range(q):
	B = copy.copy(A)
	queryi = list(map(int, input().split()))
	b = queryi[0]
	m = queryi[1]
	e = queryi[2]
	for k in range(e - b):
		pos = b + (k + e - m) % (e - b)
		B[pos] = A[b + k]
	A = copy.copy(B)
B = list(map(str, B))
print(' '.join(B))


from collections import deque
from copy import deepcopy
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	(b, m, e) = map(int, input().split())
	tmp = deepcopy(a)
	for k in range(e - b):
		a[b + (k + e - m) % (e - b)] = tmp[b + k]
print(*a)


n = int(input())
a = list(map(int, input().split()))
n = int(input())
for i in range(n):
	(b, m, e) = map(int, input().split())
	a = a[:b] + a[m:e] + a[b:m] + a[e:]
print(*a)


n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
	(b, m, e) = map(int, input().split())
	tmp = a[:]
	for k in range(e - b):
		t = b + (k + (e - m)) % (e - b)
		a[t] = tmp[b + k]
print(*a)


_ = input()
A = [int(a) for a in input().split()]
for _ in range(int(input())):
	(b, m, e) = map(int, input().split())
	t = [0] * (e - b)
	for i in range(e - b):
		j = (i + (e - m)) % (e - b)
		t[j] = A[b + i]
	A = A[:b] + t + A[e:]
print(*A, sep=' ')


input()
nums = list(map(int, input().split(' ')))
n = int(input())
for _ in range(n):
	(f, m, l) = list(map(int, input().split(' ')))
	sb = list(nums[f:l])
	r = l - m
	sb = sb[len(sb) - r:] + sb[:len(sb) - r]
	nums = nums[:f] + sb + nums[l:]
print(' '.join(map(str, nums)))


readline = open(0).readline
N = int(readline())
(*A,) = map(int, readline().split())
Q = int(readline())
for _ in range(Q):
	(b, m, e) = map(int, readline().split())
	B = A[:]
	for k in range(e - b):
		A[b + (k + (e - m)) % (e - b)] = B[b + k]
print(*A)


dist = lambda b, e, k: (k + (e - m)) % (e - b)
n = int(input())
a = list(map(int, input().split(' ')))
q = int(input())
for i in range(q):
	(b, m, e) = list(map(int, input().split(' ')))
	tmp = [None for i in range(e - b)]
	for k in range(e - b):
		tmp[dist(b, e, k)] = a[b + k]
	a[b:e] = tmp
print(' '.join(list(map(str, a))))


def resolve():
	from collections import deque
	N = int(input())
	A = [int(i) for i in input().split()]
	Q = int(input())
	ans = [i for i in range(N)]
	for _ in range(Q):
		(b, m, e) = [int(i) for i in input().split()]
		tmp = deque(ans[b:e])
		tmp.rotate(e - m)
		for i in range(b, e):
			ans[i] = tmp[i - b]
	prt = [0] * N
	for i in range(N):
		prt[i] = A[ans[i]]
	print(*prt)
resolve()


n = int(input())
a = list(map(int, input().split()))
INF = 100100100
aa = [INF for i in range(n)]
q = int(input())
for j in range(q):
	(b, m, e) = map(int, input().split())
	for i in range(n):
		if b <= i < e:
			d = b + (i - b + (e - m)) % (e - b)
			aa[d] = a[i]
	for k in range(n):
		if aa[k] == INF:
			aa[k] = a[k]
	a = list(aa)
	aa = [INF for i in range(n)]
print(a[0], end='')
for aa in a[1:]:
	print(' {}'.format(aa), end='')
print()


n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	(b, m, e) = list(map(int, input().split()))
	a = a[:b] + a[m:e] + a[b:m] + a[e:]
print(' '.join(map(str, a)))


n = int(input())
arr = list(map(int, input().split()))
nq = int(input())
for i in range(nq):
	(b, m, e) = map(int, input().split())
	arr = arr[:b] + arr[m:e] + arr[b:m] + arr[e:]
print(*arr)


n = int(input())
box = list(map(int, input().split()))
q = int(input())
for _ in range(q):
	(b, m, e) = map(int, input().split())
	_box = list(box)
	for k in range(e - b):
		_box[b + (k + (e - m)) % (e - b)] = box[b + k]
	box = _box
print(*box)