You are given a string s and should process m queries. Each query is described by two 1-based indices l_{i}, r_{i} and integer k_{i}. It means that you should cyclically shift the substring s[l_{i}... r_{i}] k_{i} times. The queries should be processed one after another in the order they are given.

One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.

For example, if the string s is abacaba and the query is l_1 = 3, r_1 = 6, k_1 = 1 then the answer is abbacaa. If after that we would process the query l_2 = 1, r_2 = 4, k_2 = 2 then we would get the string baabcaa.


-----Input-----

The first line of the input contains the string s (1 ≤ |s| ≤ 10 000) in its initial state, where |s| stands for the length of s. It contains only lowercase English letters.

Second line contains a single integer m (1 ≤ m ≤ 300) — the number of queries.

The i-th of the next m lines contains three integers l_{i}, r_{i} and k_{i} (1 ≤ l_{i} ≤ r_{i} ≤ |s|, 1 ≤ k_{i} ≤ 1 000 000) — the description of the i-th query.


-----Output-----

Print the resulting string s after processing all m queries.


-----Examples-----
Input
abacaba
2
3 6 1
1 4 2

Output
baabcaa



-----Note-----

The sample is described in problem statement.

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation


Solutions:
class ShiftCommand(object):

	def __init__(self, left, right, shift_step):
		self.left = left
		self.right = right
		self.shift_range = self.right - self.left
		self.shift_step = self._remove_circles(shift_step)

	def _remove_circles(self, shift_step):
		return shift_step % self.shift_range

	def apply_command(self, characters):
		buff = characters[self.left:self.right]
		for i in range(self.left, self.right):
			characters[i] = buff[i - self.left - self.shift_step]
		return characters
characters = list(input())
n = int(input())
for i in range(n):
	params = [int(i) for i in input().split(' ')]
	command = ShiftCommand(params[0] - 1, params[1], params[2])
	characters = command.apply_command(characters)
print(''.join(characters))


s = input()
for _ in range(int(input())):
	(l, r, k) = [int(x) for x in input().split()]
	if k == 0:
		continue
	size = r - l + 1
	k = k % size
	s = s[0:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


s = input()
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split())
	ds = k % (r - l + 1)
	s = s[:l - 1] + s[r - ds:r] + s[l - 1:r - ds] + s[r:]
print(s)


s = input()
m = int(input())
x = list(s)
for i in range(m):
	(l, r, k) = map(int, input().split(' '))
	r -= 1
	l -= 1
	k = k % (r - l + 1)
	x[l:r + 1] = x[r - k + 1:r + 1] + x[l:r - k + 1]
print(''.join((str(x) for x in x)))


def cyclestring(s, n, k):
	k = k % n
	return s[n - k:] + s[:n - k]

def cyclesubstring(s, l, r, k):
	return s[:l - 1] + cyclestring(s[l - 1:r], r - l + 1, k) + s[r:]
s = input()
steps = int(input())
for _ in range(steps):
	(l, r, k) = map(int, input().split())
	s = cyclesubstring(s, l, r, k)
print(s)


string = input()
letters = []
for i in string:
	letters.append(i)
m = int(input())
for i in range(m):
	order = input().split()
	for (k, j) in enumerate(order):
		order[k] = int(j)
	space = order[1] - order[0] + 1
	distance = order[2] % space
	new = [0] * (order[1] - order[0] + 1)
	for j in range(space):
		if j - distance < 0:
			new[j] = letters[j + order[0] - 1 - distance + space]
		else:
			new[j] = letters[j + order[0] - 1 - distance]
	letters = letters[:order[0] - 1] + new + letters[order[1]:]
print(''.join(letters))


s = list(input())
n = int(input())
for i in range(n):
	w = input().split()
	(l, r, k) = (int(w[0]), int(w[1]), int(w[2]))
	k = k % (r - l + 1)
	s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
for j in range(len(s)):
	print(s[j], end='')


s = list(input())
le = len(s)
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	s[l - 1:r] = s[r - k:r] + s[l - 1:r - k]
print(''.join(s))


s = list(input())
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	k %= r - l
	(beg, to_rev, end) = (s[:l], s[l:r], s[r:])
	s = beg + list(reversed(list(reversed(to_rev[:-k])) + list(reversed(to_rev[-k:])))) + end
print(''.join(s))


s = input()
m = int(input())
while m:
	(l, r, k) = map(int, input().split())
	k = k % (r - l + 1)
	while k:
		s = s[0:l - 1] + s[r - 1] + s[l - 1:r - 1] + s[r:]
		k -= 1
	m -= 1
print(s)


s = list(input())
q = int(input())
s.insert(0, ' ')
while q:
	q -= 1
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	s = s[:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:]
print(''.join(s[1:]))


s = input()
queries = int(input())
query_list = []
for i in range(queries):
	query_list.append((int(i) for i in input().split(' ')))

def process_query(s, query):
	query = list(query)
	l = query[0]
	r = query[1]
	cycle_size = r - l + 1
	k = query[2] % cycle_size
	frag = s[l - 1:r]
	return s[:l - 1] + frag[-k:] + frag[:-k] + s[r:]
for q in query_list:
	s = process_query(s, q)
print(s)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	s = str(input())
	m = int(input())
	for i in range(m):
		lrk = list(map(int, input().split()))
		(l, r, k) = (lrk[0], lrk[1], lrk[2])
		t = s[l - 1:r]
		x = k % (r - l + 1)
		if x != 0:
			s = s[:l - 1] + t[len(t) - x:] + t[:len(t) - x] + s[r:]
	print(s)
main()


def string(s, m):
	l = m[0]
	r = m[1]
	k = m[2]
	s1 = s[l - 1:r]
	s2 = []
	for i in range(r - l + 1):
		s2.append(0)
	for i in range(r - l + 1):
		s2[(i + k) % len(s1)] = s1[i]
	return s[0:l - 1] + ''.join(s2) + s[r:]
s = input()
n = int(input())
for i in range(n):
	m = list(map(int, input().split()))
	s = string(s, m)
print(s)


R = input
s = R()
for _ in '1' * int(R()):
	(l, r, k) = map(int, R().split())
	l -= 1
	a = s[l:r]
	k %= len(a)
	s = s[:l] + a[-k:] + a[:-k] + s[r:]
print(s)


st = input()
for i in range(int(input())):
	c = input().split()
	p = st[int(c[0]) - 1:int(c[1])]
	k = int(c[2]) % len(p)
	p = p[-k:] + p[:-k]
	st = st[:int(c[0]) - 1] + p + st[int(c[1]):]
print(st)


def arrange(array, k):
	a = k % len(array)
	ans = array[len(array) - a:] + array[:len(array) - a]
	return ans
s = input()
m = int(input())
for i in range(m):
	(l, r, k) = list(map(int, input().split()))
	s = s[:l - 1] + arrange(s[l - 1:r], k) + s[r:]
print(s)


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():

	def R(p, n, k):
		return p[-k:] + p[:-k]
	s = st()
	q = inp()
	for i in range(q):
		(a, b, c) = mp()
		a -= 1
		b -= 1
		x = b - a + 1
		c = c % x
		y = R(s[a:b + 1], x, c)
		s = s[:a] + y + s[b + 1:]
	print(''.join(s))
for _ in range(1):
	solve()


s = input()
n = int(input())
for x in range(n):
	(l, r, a) = map(int, input().split())
	b = a % (r - l + 1)
	s = s[:l - 1] + s[r - b:r] + s[l - 1:r - b] + s[r:]
print(s)


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = [int(c) for c in input().split()]
	k = k % (r - l + 1)
	s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


word = list(input())
nShifts = int(input())
for _ in range(nShifts):
	(start, end, shift) = [int(x) for x in input().split()]
	mod = end - start + 1
	temp = word[start - 1:end]
	for i in range(mod):
		goal = start - 1 + (i + shift) % mod
		word[goal] = temp[i]
for letter in word:
	print(letter, end='')
print()


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def rotate_seg(s, left, right, k):
	length = right - left + 1
	for i in range(gcd(length, k)):
		start = left + i
		cur = i
		next_element = (cur - k) % length
		while next_element + left != start:
			tmp = s[next_element + left]
			s[next_element + left] = s[cur + left]
			s[cur + left] = tmp
			cur = next_element
			next_element = (cur - k) % length
input_string = list(input())
queries = int(input())
for query in range(queries):
	(l, r, k) = map(int, input().split())
	rotate_seg(input_string, l - 1, r - 1, k)
print(''.join(input_string))


def permutation(s, k):
	return s[-k:] + s[:-k]
s = input()
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	k = k % (r - l + 1)
	s = s[:l - 1] + permutation(s[l - 1:r], k) + s[r:]
print(s)


def sint():
	return int(input())

def sara():
	return list(map(int, input().split()))

def sstr():
	s = input()
	return list(s[:len(s)])

def sints():
	return map(int, input().split())

def solve():
	s = sstr()
	q = sint()
	for i in range(q):
		(l, r, k) = sints()
		rng = r - l + 1
		ts = list(s)
		k %= rng
		ind = (k + l - 1) % r
		for i in range(l - 1, r):
			if ind < l - 1:
				ind += l - 1
			s[ind] = ts[i]
			ind = (ind + 1) % r
	ln = len(s)
	for i in range(ln):
		print(s[i], end='')
	print('')
solve()


S = str(input())
n = int(input())
for m in range(n):
	(l, r, k) = list(map(int, input().split()))
	if l == r:
		pass
	else:
		k %= r - l + 1
		S = S[:l - 1] + S[r - k:r] + S[l - 1:r - k] + S[r:]
print(S)


s = input()
for it in range(int(input())):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


def main():
	string = list(input())
	m = int(input())
	for _ in range(m):
		(l, r, k) = map(int, input().split())
		l -= 1
		r -= 1
		total = r - l + 1
		k = k % total
		diff = total - k
		string_copy = string[l:r + 1][:]
		string[r - diff + 1:r + 1] = string_copy[:diff]
		string[l:l + k] = string_copy[total - k:total]
	print(''.join(string))
main()


def apply_queries(s, queries):
	for (l, r, k) in queries:
		k %= r - l + 1
		s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
	return s
w = input()
n = int(input())
queries = []
for i in range(n):
	inp = input()
	queries.append(list(map(int, inp.split(' '))))
print(apply_queries(w, queries))


from collections import deque

def solve(s, l, r, k):
	(s1, s2) = (s[:l - 1], s[r:])
	tmp = s[l - 1:r]
	k %= r - l + 1
	d = deque(tmp)
	for _ in range(k):
		x = d[-1]
		d.pop()
		d.appendleft(x)
	tmp = ''.join(d)
	return ''.join([s1, tmp, s2])
s = input()
m = int(input())
for _ in range(m):
	(l, r, k) = list(map(int, input().split()))
	s = solve(s, l, r, k)
print(s)


s = [ch for ch in input()]
d = dict()
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	_len = r - l + 1
	k %= _len
	for x in range(_len):
		_x = (x + k) % _len
		d[l + _x] = s[l + x]
	for k in d:
		s[k] = d[k]
	d.clear()
print(''.join(s))


s = list(input())
m = int(input())
while m > 0:
	m = m - 1
	(l, r, k) = map(int, input().split())
	d = k % (r - l + 1)
	if d == 0:
		continue
	fr = s[r - d:r]
	sc = s[l - 1:r - d]
	s[l - 1:r] = fr + sc
for i in s:
	print(i, end='')


def rot(s, pos):
	return s[len(s) - pos:] + s[:len(s) - pos]
s = input()
x = int(input())
s = [''] + list(s)
for i in range(x):
	(a, b, c) = list(map(int, input().split(' ')))
	s[a:b + 1] = rot(s[a:b + 1], c % (b - a + 1))
print(''.join(s))


s = input()
t = int(input())
for i in range(t):
	(l, r, k) = map(int, input().split())
	temp = s[l - 1:r]
	if k > r - l + 1:
		k = k % (r - l + 1)
	temp = temp[-k:] + temp[:-k]
	s = s[:l - 1] + temp + s[r:]
print(s)


s = list(str(input()))
m = int(input())
import copy
for i in range(m):
	(l, r, k) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	t = copy.copy(s)
	for j in range(l, r + 1):
		t[l + (j - l + k) % (r - l + 1)] = s[j]
	s = copy.copy(t)
print(''.join(s))


import sys
rl = lambda : next(sys.stdin).strip()
s = rl()
n = len(s)
m = int(rl())
for _ in range(m):
	(l, r, k) = map(int, rl().split())
	l -= 1
	k %= r - l
	if k == 0:
		continue
	t = s[:l]
	for i in range(r - l):
		t += s[l + (r - l - k + i) % (r - l)]
	t += s[r:]
	s = t
print(s)


s = input()
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	(l, r, ln) = (l - 1, r - 1, r - l + 1)
	k %= ln
	s = s[:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:]
print(s)


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	ss = s[l - 1:r]
	n = len(ss)
	k %= n
	s = s[:l - 1] + ss[n - k:] + ss[:n - k] + s[r:]
print(s)


import sys

def cyclic(s, k):
	n = len(s)
	k %= n
	return s[-k:] + s[0:-k]
s = sys.stdin.readline()
m = int(sys.stdin.readline())
for it in range(m):
	(l, r, k) = map(int, sys.stdin.readline().split())
	s = s[0:l - 1] + cyclic(s[l - 1:r], k) + s[r:]
print(s)


def shift(s, amt):
	return s[amt:] + s[:amt]

def main():
	s = input()
	q = int(input())
	for _ in range(q):
		(l, r, k) = map(int, input().split())
		l -= 1
		k %= r - l
		s = s[:l] + shift(s[l:r], r - l - k) + s[r:]
	print(s)
main()


def tr(s, n=1):
	n = len(s) - n
	return s[n:] + s[:n]

def pr(vs, l, r, k):
	vs[0] = vs[0][:l] + tr(vs[0][l:r], k % (r - l)) + vs[0][r:]
vs = [input()]
n = int(input())
vc = []
for c in range(n):
	vc.append([int(x) for x in input().split()])
for c in vc:
	pr(vs, c[0] - 1, c[1], c[2])
print(vs[0])


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
s = input().strip()
n = I()
for i in range(n):
	(l, r, k) = M()
	k = k % (r - l + 1)
	x = s[l - 1:r]
	y = ''
	for j in range(len(x)):
		y += x[(j - k) % len(x)]
	s = s[:l - 1] + y + s[r:]
print(s)


s = input()
for i in range(int(input())):
	(li, ri, ki) = map(int, input().split())
	shift = ki % (ri - li + 1)
	s = s[:li - 1] + s[li - 1:ri][-shift:] + s[li - 1:ri][:-shift] + s[ri:]
print(s)


stri = input()
t = int(input())
for _ in range(t):
	(i, j, c) = [int(i) for i in input().split()]
	aux = stri[i - 1:j]
	c = c % (abs(i - j) + 1)
	aux = aux[-1 * c:] + aux[:-1 * c]
	stri = stri[0:i - 1] + aux + stri[j:len(stri)]
print(stri)


n = input()
x = int(input())
for _ in range(x):
	(a, b, c) = map(int, input().split())
	m = n[a - 1:b]
	k = c % len(m)
	l = ''
	for j in range(len(m)):
		l += m[(-k + j) % len(m)]
	n = n[:a - 1] + l + n[b:]
print(n)


s = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	l += -1
	r += -1
	ln = r - l + 1
	k %= ln
	tmp = []
	for i in s:
		tmp.append(i)
	for j in range(l, r + 1):
		if j + k <= r:
			tmp[j + k] = s[j]
		else:
			tmp[l - 1 + j + k - r] = s[j]
	for i in range(len(s)):
		s[i] = tmp[i]
print(*s, sep='')


s = list(input())
for i in range(int(input())):
	(l, r, k) = list(map(int, input().split()))
	k %= r - l + 1
	if k > 0:
		s[l - 1:r] = s[r - k:r] + s[l - 1:r - k]
print(''.join(s))


s = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	n = r - l + 1
	l -= 1
	r -= 1
	k = k % n
	temp = []
	for j in range(r - k + 1, r + 1):
		temp.append(s[j])
	for j in range(r - k, l - 1, -1):
		s[j + k] = s[j]
	for j in range(l, l + k):
		s[j] = temp[j - l]
print(''.join(s))


a = list(input())
n = len(a)
t = int(input())
for y in range(t):
	(l, r, k) = map(int, input().split())
	new = [0 for i in range(n)]
	for i in range(l - 1):
		new[i] = a[i]
	if r != l:
		k %= r - l + 1
		st = r - 1 - k
		for i in range(r - 1, l - 2, -1):
			new[i] = a[st]
			st -= 1
			if st < l - 1:
				st = r - 1
		for i in range(r, n):
			new[i] = a[i]
		a = new
print(''.join(a))


from collections import deque
s = list(input())
m = int(input())
for _ in range(m):
	(l, r, v) = map(int, input().split())
	t = s[l - 1:r]
	t = deque(s[l - 1:r])
	t.rotate(v)
	s[l - 1:r] = list(t)[:]
print(''.join(s))


s = input()
aa = list(s)
bb = list(s)
length = len(s)
q = int(input())
while q != 0:
	a = input().split()
	a[0] = int(a[0]) - 1
	a[1] = int(a[1]) - 1
	a[2] = int(a[2])
	count = 0
	temp = a[2] % (a[1] - a[0] + 1)
	lenn = a[1] - a[0] + 1
	for i in range(a[0] + temp, a[0] + lenn):
		bb[i] = aa[a[0] + count]
		count += 1
	for i in range(a[0], a[0] + temp):
		bb[i] = aa[a[0] + count]
		count += 1
	for i in range(length):
		aa[i] = bb[i]
	q = q - 1
for i in range(length):
	print(bb[i], end='')
print()


s = input()
for _ in range(int(input())):
	(L, R, K) = map(int, input().split())
	(L, K) = (L - 1, K % (R - L + 1))
	sub = s[L:R]
	s = s[:L] + sub[-K:] + sub[:-K] + s[R:]
print(s)


import sys
s = list(sys.stdin.readline())
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	a = s[l:r + 1]
	for i in range(l, r + 1):
		s[i] = a[i - l - k % (r + 1 - l)]
print(''.join(s))


my_str = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = list(map(int, input().split()))
	my_buf = my_str[l - 1:r].copy()
	k = k % len(my_buf)
	cyclic = my_buf[:-k]
	del my_buf[:-k]
	my_buf += cyclic
	my_str[l - 1:r] = my_buf.copy()
print(''.join(my_str))


def question(l, r, k, cur_pos):
	if cur_pos > r or cur_pos < l:
		return cur_pos
	else:
		(adj_l, adj_r, adj_cur) = (0, r - l, cur_pos - l)
		length = r - l + 1
		final_pos = (adj_cur + k) % length
		return final_pos + l

def solve():
	string = [str(x) for x in str(input())]
	answer = string[:]
	q = int(input())
	queries = []
	for query in range(q):
		(l, r, k) = map(int, input().split())
		queries.append((l, r, k))
	for (index, letter) in enumerate(string):
		cur_pos = index + 1
		for element in queries:
			(l, r, k) = element
			cur_pos = question(l, r, k, cur_pos)
		answer[cur_pos - 1] = letter
	return ''.join(answer)
print(solve())


import sys
input = sys.stdin.readline
s = list(input().strip())
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	k %= r - l + 1
	s = s[:l] + s[r + 1 - k:r + 1] + s[l:r + 1 - k] + s[r + 1:]
print(''.join(s))


s = input()
n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	(l, r, k) = info[i]
	l -= 1
	shift_len = r - l
	shift = k % (r - l)
	s = s[0:l] + s[r - shift:r] + s[l:r - shift] + s[r:]
print(s)


s = input()
a = []
for i in range(len(s)):
	a.append([i, s[i]])
for _ in range(int(input())):
	(l, r, k) = [int(x) for x in input().split()]
	size = r - l + 1
	l -= 1
	k = k % size
	if k == 0:
		continue
	for i in range(l, r):
		a[i][0] = l + (i - l + k) % size
	a.sort(key=lambda x: x[0])
st = ''
for i in range(len(a)):
	st += a[i][1]
print(st)


def provide_curr(string, num_ops):
	result = [0] * len(string)
	counter = num_ops
	for (i, letter) in enumerate(string):
		if counter >= len(result):
			counter = 0
		result[counter] = letter
		counter += 1
	return ''.join(result)

def solve():
	string = input()
	m = int(input())
	for _ in range(m):
		(l, r, k) = list(map(int, input().split(' ')))
		str_length = r - l + 1
		num_ops = k
		if k > str_length:
			num_ops = k % str_length
		curr = string[l - 1:r]
		res = provide_curr(curr, num_ops)
		string = string[:l - 1] + res + string[r:]
	return string
print(solve())


s = input()
for i in range(int(input())):
	(l, r, k) = map(int, input().split())
	k = k % (r - l + 1)
	rotate = s[l - 1:r]
	rotate = rotate[-k:] + rotate[:-k]
	s = s[:l - 1] + rotate + s[r:]
print(s)


s = str(input())
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	st = ''
	st += s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
	s = st
print(s)


s = input()
q = int(input())
for t in range(q):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	l -= 1
	a = s[0:l]
	b = s[l:r - k]
	c = s[r - k:r]
	d = s[r:len(s)]
	s = a + c + b + d
print(s)


from random import *

class Node:

	def __init__(self, d):
		self.dat = d
		self.cnt = 1
		self.pri = randrange(1 << 20)
		self.L = self.R = None

	def recnt(self):
		self.cnt = getcnt(self.L) + getcnt(self.R) + 1

def getcnt(node):
	return 0 if node == None else node.cnt

def mrg(Fr, Sr):
	if Fr == None:
		return Sr
	if Sr == None:
		return Fr
	if Fr.pri > Sr.pri:
		Sr.L = mrg(Fr, Sr.L)
		Sr.recnt()
		return Sr
	Fr.R = mrg(Fr.R, Sr)
	Fr.recnt()
	return Fr

def splt(Rt, k):
	if k == 0:
		return (None, Rt)
	if getcnt(Rt) <= k:
		return (Rt, None)
	if getcnt(Rt.L) >= k:
		(Fr, Rt.L) = splt(Rt.L, k)
		Rt.recnt()
		return (Fr, Rt)
	(Rt.R, Sr) = splt(Rt.R, k - getcnt(Rt.L) - 1)
	Rt.recnt()
	return (Rt, Sr)

def out(Rt):
	if Rt == None:
		return
	out(Rt.L)
	print(Rt.dat, end='')
	out(Rt.R)
l = list(input())
root = None
for x in l:
	root = mrg(root, Node(x))
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	(root, Sr) = splt(root, r)
	(Fr, root) = splt(root, l - 1)
	k %= r - l + 1
	(F, S) = splt(root, getcnt(root) - k)
	root = mrg(Fr, mrg(mrg(S, F), Sr))
out(root)


str = input()
n = int(input())
for _ in range(n):
	(l, r, k) = map(int, input().split())
	if l < r:
		k %= r - l + 1
		str = str[:l - 1] + str[r - k:r] + str[l - 1:r - k] + str[r:]
print(str)


s = input()
res = [i for i in s]
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	k = k % (r - l + 1)
	n = r - l + 1
	ans = [0] * n
	for i in range(l, r + 1):
		if i - l < k:
			ans[i - l] = res[r - l + 1 - k + i]
		else:
			ans[i - l] = res[i - k]
	res[l:r + 1] = ans
print(''.join(res))


s = input()
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split(' '))
	l -= 1
	r -= 1
	t = s[l:r + 1]
	k = k % len(t)
	while k > 0:
		t = t[-1] + t[:len(t) - 1]
		k -= 1
	s = s[:l] + t + s[r + 1:]
print(s)


s = input().strip()
n = int(input())
for i in range(n):
	(f, t, k) = map(int, input().split())
	l = t - f + 1
	f -= 1
	k %= l
	if k != 0:
		s = s[:f] + s[t - k:t] + s[f:f + l - k] + s[t:]
print(s)


import sys
input = sys.stdin.readline
S = list(input())[:-1]
Q = int(input())
for _ in range(Q):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	T = S[:]
	for i in range(l - 1, r):
		x = i
		y = (i + k - (l - 1)) % (r - l + 1)
		T[y + l - 1] = S[x]
	S = T
print(''.join(S))


word = list(input())
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	word[l - 1:r] = word[r - k:r] + word[l - 1:r - k]
print(''.join(word))


x = input()
m = int(input())
yo = list(x)
yy = list(x)
while m > 0:
	m = m - 1
	hello = input().split()
	l = int(hello[0])
	r = int(hello[1])
	k = int(hello[2])
	l = l - 1
	r = r - 1
	temp = r - l + 1
	for i in range(0, len(x)):
		if i >= l and i <= r:
			yo[(i - l + k) % temp + l] = yy[i]
		else:
			yo[i] = yy[i]
	yy = list(yo)
for i in range(0, len(yy)):
	print(yy[i], end='')
print()


import sys

def pos(curr, l, r, k):
	k %= r - l + 1
	res = curr + k
	if res > r:
		res = l + (res - r) - 1
	return res

def build(inStr, l, r, k):
	lst = inStr[:]
	for i in range(l, r + 1):
		to = pos(i, l, r, k)
		lst[to] = inStr[i]
	return lst
mystr = list(input())
m = input()
m = int(m)
for i in range(m):
	stuff = input().split()
	l = int(stuff[0])
	r = int(stuff[1])
	k = int(stuff[2])
	l -= 1
	r -= 1
	mystr = build(mystr, l, r, k)
ans = ''
for char in mystr:
	ans += char
print(ans)


s = input().strip()
M = int(input())
for m in range(M):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	substring = s[l - 1:r]
	if k < (r - l + 1) // 2:
		for i in range(k):
			substring = substring[-1] + substring[:-1]
	else:
		k = r - l + 1 - k
		for i in range(k):
			substring = substring[1:] + substring[0]
	s = s[:l - 1] + substring + s[r:]
print(s)


import sys

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip('\n')
s = list(input())
n = int(input())
for i in range(n):
	(l, r, k) = get_ints()
	rt = r - l + 1
	k %= rt
	change = []
	for i in range(k):
		change.append(s[r - 1 - i])
	temp = s[l - 1:r - k]
	s[l - 1:r] = change[::-1] + temp
print(''.join(s))


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	t = s[l - 1:r]
	s = s[:l - 1] + t[len(t) - k:] + t[:len(t) - k] + s[r:]
print(s)


v = [x for x in input().strip()]
queries = int(input())

def reverse(v, left, right):
	while left < right:
		(v[left], v[right]) = (v[right], v[left])
		left += 1
		right -= 1
	return v
for _ in range(queries):
	(l, r, s) = [int(x) for x in input().split()]
	l = l - 1
	r = r - 1
	s = s % (r - l + 1)
	mid = r - s
	v = reverse(v, l, mid)
	v = reverse(v, mid + 1, r)
	v = reverse(v, l, r)
print(''.join(v))


string = input()
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split())
	length = r - l + 1
	k %= length
	if k != 0:
		rot = string[l - 1:r][-k:] + string[l - 1:r][:length - k]
		string = string[:l - 1] + rot + string[r:]
print(string)


import sys

class Scanner:

	def __init__(self):
		self.current_tokens = []

	def remaining_tokens(self):
		return len(self.current_tokens)

	def nextline(self):
		assert self.remaining_tokens() == 0, 'Reading next line with remaining tokens'
		return input()

	def nexttokens(self):
		return self.nextline().split()

	def nexttoken(self):
		if len(self.current_tokens) == 0:
			self.current_tokens = self.nexttokens()
		assert self.remaining_tokens() > 0, 'Not enough tokens to parse.'
		return self.current_tokens.pop(0)

	def nextints(self, n=-1):
		if n == -1:
			return list(map(int, self.nexttokens()))
		else:
			return [self.nextint() for i in range(n)]

	def nextint(self):
		return int(self.nexttoken())

def quit():
	sys.exit(0)
stdin = Scanner()
nextint = stdin.nextint
nextints = stdin.nextints
nextline = stdin.nextline

def shift(s, l, r, k):
	l -= 1
	r -= 1
	o = []
	for c in s[l:r + 1]:
		o.append(c)
	ns = [''] * (r - l + 1)
	for i in range(r - l + 1):
		ns[(i + k) % (r - l + 1)] = o[i]
	return s[:l] + ''.join(ns) + s[r + 1:]
S = nextline()
m = nextint()
for i in range(m):
	S = shift(S, nextint(), nextint(), nextint())
print(S)


a = list(input())
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	a = a[:l - 1] + a[r - k:r] + a[l - 1:r - k] + a[r:]
print(*a, sep='')


def ckl(s, l, r, k):
	l -= 1
	r -= 1
	k %= r - l + 1
	return s[:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:]
s = input()
t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	s = ckl(s, a, b, c)
print(s)


def main():
	s = input()
	m = int(input())
	for i in range(m):
		(l, r, k) = list(map(int, input().split(' ')))
		l -= 1
		k = r - k % (r - l)
		s = s[:l] + s[k:r] + s[l:k] + s[r:]
	print(s)
main()


s = input()
n = int(input())
for i in range(n):
	(a, b, k) = map(int, input().split())
	s = s[:a - 1] + s[a - 1:b][-(k % (b - a + 1)):] + s[a - 1:b][:-(k % (b - a + 1))] + s[b:]
print(s)


import sys
import math

def main():
	s = sys.stdin.readline().strip()
	n = int(sys.stdin.readline().strip())
	for _ in range(n):
		(l, r, k) = map(int, sys.stdin.readline().strip().split()[:3])
		k %= r - l + 1
		s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
	print(s)
main()


s = input()
m = int(input())
for _ in range(m):
	(l, r, k) = input().split()
	(l, r) = (int(l) - 1, int(r) - 1)
	lr = r - l + 1
	k = int(k) % lr
	s = s[0:l] + s[l + (lr - k) % lr:r + 1] + s[l:l + (lr - k) % lr] + s[r + 1:]
print(s)


s = input()
n = int(input())
for _ in range(n):
	(l, r, k) = [int(x) for x in input().split()]
	l -= 1
	d = r - l
	sh = k % d
	x = s[:l] + s[r - sh:r] + s[l:r - sh] + s[r:]
	s = x
print(s)


s = input()
n = int(input())
for _ in range(0, n):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	t = s[l:r + 1]
	k %= len(t)
	if k == 0:
		k = len(t)
	s = s[0:l] + t[-k:] + t[0:len(t) - k] + s[r + 1:]
print(s)


s = input()
q = int(input())
while q > 0:
	q -= 1
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	l -= 1
	a = s[:l]
	b = s[l:r - k]
	c = s[r - k:r]
	d = s[r:]
	s = a + c + b + d
print(s)


import sys
s = list(sys.stdin.readline())
m = int(sys.stdin.readline())
for _ in range(m):
	(l, r, k) = map(int, sys.stdin.readline().split())
	l -= 1
	k = k % (r - l)
	if k:
		part = s[l:r]
		s[l:r] = part[-k:] + part[:-k]
print(''.join(s))


s = input()
m = int(input())
for _ in range(m):
	(left, right, k) = map(int, input().split())
	left -= 1
	right -= 1
	k %= right - left + 1
	s = s[:left] + s[right - k + 1:right + 1] + s[left:right - k + 1] + s[right + 1:]
print(s)


word = str(input())
t = int(input())
for case in range(t):
	(l, r, k) = map(int, input().split())
	start = word[0:l - 1]
	middle = word[l - 1:r]
	end = word[r:] if r != len(word) else ''
	net_shift = k % len(middle)
	middle = middle[len(middle) - net_shift:] + middle[:len(middle) - net_shift]
	word = start + middle + end
print(word)


s = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	haba = r - l + 1
	k %= haba
	t = s[l - 1:r]
	for j in range(haba):
		s[j + l - 1] = t[(j - k) % haba]
print(''.join(s))


def do_shift(l, r, k):
	sub_s = s[l:r + 1]
	m = len(sub_s) - k % len(sub_s)
	s[l:r + 1] = sub_s[m:] + sub_s[:m]
s = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	do_shift(l - 1, r - 1, k)
print(''.join(s))


string = list(input())
tests = int(input())
for i in range(tests):
	(l, r, times) = map(int, input().split())
	l -= 1
	temp = string[l:r]
	k = (times - 1) % (r - l)
	for i in range(len(temp)):
		k += 1
		k = k % (r - l)
		string[l + k] = temp[i]
print(''.join(string))


s = input()
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	p = s[l - 1:r]
	k = k % len(p)
	p = p[-k:] + p[:-k]
	s = s[:l - 1] + p + s[r:]
print(s)


s = input()
q = int(input())
for i in range(q):
	a = list(map(int, input().split()))
	l = a[0]
	r = a[1]
	k = a[2]
	s2 = s[l - 1:r]
	n = len(s2)
	k = k % n
	ls = s2[:n - k]
	rs = s2[n - k:]
	s = s[:l - 1] + rs + ls + s[r:]
print(s)


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	l = l - 1
	r = r - 1
	sub = s[l:r + 1]
	k = k % len(sub)
	part1 = sub[0:len(sub) - k]
	part2 = sub[len(sub) - k:len(sub)]
	sub = part2 + part1
	s = list(s)
	s[l:r + 1] = sub[0:len(sub)]
	s = ''.join(s)
print(s)


import itertools as it
import functools
import operator
import collections
import math
import sys

def cycle_shift(s, k):
	n = len(s)
	k %= n
	return s[n - k:] + s[:n - k]

def solve(triples, s, m):
	for (l, r, k) in triples:
		s = s[:l - 1] + cycle_shift(s[l - 1:r], k) + s[r:]
	return s

def p(*args, **kwargs):
	return print(*args, file=sys.stderr, **kwargs)

def main():
	s = input()
	m = int(input())
	triples = [tuple((int(c) for c in input().strip().split())) for _ in range(m)]
	result = solve(triples, s, m)
	print(result)

def __starting_point():
	main()
__starting_point()


def Input():
	tem = input().split()
	ans = []
	for it in tem:
		ans.append(int(it))
	return ans
from collections import Counter
s = input()
T = Input()[0]
n = len(s)
for t in range(T):
	(l, r, k) = Input()
	l -= 1
	r -= 1
	span = r - l + 1
	if span < 2:
		continue
	k = k % span
	s = s[:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:]
print(s)


s = input()
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	k %= r - l + 1
	t = s[l:r + 1]
	t = t[-k:] + t[:-k]
	s = s[:l] + t + s[r + 1:]
print(s)


s = str(input())
if len(s) > 1:
	s = '$' + s + '$'
	t = int(input())
	la = len(s)
	for i in range(t):
		(l, r, k) = [int(x) for x in input().split()]
		if r - l != 0:
			k = k % (r - l + 1)
			temp = s[:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:]
			s = temp
	print(s[1:len(s) - 1])
else:
	print(s)


def cyclic_shift(a, b, k):
	global s
	if a == b:
		return
	k = k % (b - a + 1)
	if k == 0:
		return
	p = s[a - 1:b]
	p.reverse()
	pl = p[:k]
	pl.reverse()
	pr = p[k:]
	pr.reverse()
	s[a - 1:b] = pl + pr
s = list(input())
for i in range(int(input())):
	q = list(map(int, input().split()))
	cyclic_shift(q[0], q[1], q[2])
print(''.join(s))


def main():
	s = input()
	m = int(input())
	if len(s) < 1 or len(s) > 10000:
		return
	if m < 1 or m > 300:
		return
	s = list(s)
	while m != 0:
		(l, r, k) = list(map(int, input().split()))
		substr = s[l - 1:r].copy()
		N = len(substr)
		k = k % N
		sub1 = substr[N - k:].copy()
		sub1.reverse()
		substr[N - k:] = sub1
		sub2 = substr[:N - k].copy()
		sub2.reverse()
		substr[:N - k] = sub2
		substr.reverse()
		s[l - 1:r] = substr
		m -= 1
	print(''.join(s))
main()


s = input()
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	if len(s) == 1:
		continue
	elif r - l > 0:
		k = k % (r - l + 1)
		s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


S = input()
N = int(input())
for _ in range(N):
	(l, r, k) = map(lambda x: int(x) - 1, input().split())
	x = r - k % (r + 1 - l)
	S = S[:l] + S[x:r + 1] + S[l:x] + S[r + 1:]
print(S)


string = [ch for ch in input()]
tasks = int(input())
for _ in range(tasks):
	(s, e, k) = map(int, input().split())
	k = k % (e - s + 1)
	string = string[:s - 1] + string[e - k:e] + string[s - 1:e - k] + string[e:]
print(*string, sep='')


from sys import stdin, stdout
a = list(stdin.readline())
for _ in ' ' * int(stdin.readline()):
	(x, y, z) = map(int, stdin.readline().split())
	x -= 1
	y -= 1
	l = y - x + 1
	k = [''] * l
	z %= l
	for i in range(x, y + 1):
		k[(i - x + z) % l] = a[i]
	for i in range(l):
		a[i + x] = k[i]
stdout.write(''.join(a))


s = input()
count = int(input())
for m in range(count):
	inputs = tuple(map(int, input().split()))
	(l, r, k) = inputs
	targetString = s[l - 1:r]
	newString = ''
	k = k % len(targetString)
	for i in range(len(targetString)):
		newString += targetString[(len(targetString) - k + i) % len(targetString)]
	s = s[:l - 1] + newString + s[r:]
print(s)


def rotatelist(s, l, r, k):
	(length, d) = (r - l + 1, {})
	i = k % length
	d[i] = s[0:l] + s[r - i + 1:r + 1] + s[l:r - i + 1] + s[r + 1:]
	return d[i]
s = input()
for i in range(int(input())):
	(l, r, k) = map(int, input().split())
	s = rotatelist(s, l - 1, r - 1, k)
print(s)


q = [0] + [str(x) for x in input()]
for _ in range(int(input())):
	(l, r, k) = [int(x) for x in input().split()]
	lstring = r - l + 1
	ltemp = q[1:l]
	rtemp = q[r + 1:]
	mtemp = q[l:r + 1]
	change = lstring - k % lstring
	if change:
		change -= 1
		temp = mtemp[change + 1:] + mtemp[:change + 1]
		q = [0] + ltemp + temp + rtemp
q = q[1:]
for x in q:
	print(x, end='')
print()


def shift(s, l, r, k):
	k = k % (r - l + 1)
	cp = s[l:r + 1]
	for i in range(l, r + 1):
		nxt = i + k
		if nxt > r:
			nxt = l + nxt - r - 1
		s[nxt] = cp[i - l]
s = list(input())
q = int(input())
for i in range(q):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	shift(s, l, r, k)
for i in s:
	print(i, end='')
print()


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = map(lambda x: int(x) - 1, input().split())
	k += 1
	d = r - l + 1
	k %= d
	s = s[0:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:]
print(s)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
s = STR()
m = INT()
for i in range(m):
	(l, r, k) = MAP()
	s2 = ''
	x = r - l + 1
	y = k % x
	if y != 0:
		l -= 1
		r -= 1
		for j in range(r, -1, -1):
			if len(s2) == y:
				break
			s2 = s[j] + s2
		s = s[:l] + list(s2) + s[l:r - y + 1] + s[r + 1:]
print(''.join(s))


import sys

def rotate(word, rot):
	rotated_word = [0 for _ in word]
	for pos in range(len(word)):
		new_pos = (pos + rot) % len(word)
		rotated_word[new_pos] = word[pos]
	return rotated_word
input_file = sys.stdin
word = list(input_file.readline().rstrip())
input_file.readline()
for line in input_file.readlines():
	(left, right, rot) = map(int, line.rstrip().split())
	(left, right) = (left - 1, right - 1)
	rotated_word = rotate(word[left:right + 1], rot)
	for pos in range(len(rotated_word)):
		word[left + pos] = rotated_word[pos]
print(''.join(word))


s = input()
n = int(input())
ln = len(s)
for i in range(n):
	(l, r, k) = map(int, input().split(' '))
	k %= r - l + 1
	p = s[l - 1:r]
	s = s[0:l - 1] + p[-k:] + p[:-k] + s[r:]
print(s)


s = input()

def shift(x, k):
	x = x[-k:] + x[:-k]
	return x
for i in range(int(input())):
	(l, r, k) = tuple(map(int, input().split()))
	l -= 1
	k %= r - l
	s = s[:l] + shift(s[l:r], k) + s[r:]
print(s)


from collections import deque
s = input()
m = int(input())
for i in range(m):
	lst = list(map(int, input().split()))
	(l, r, k) = (lst[0] - 1, lst[1], lst[2])
	d = deque(s[l:r])
	for p in range(k % (r - l)):
		d.appendleft(d.pop())
	s = s[:l] + ''.join(d) + s[r:]
print(s)


from collections import deque
s = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = (int(x) for x in input().split())
	k = k % (r - l + 1)
	s2 = deque(s[l - 1:r])
	s2.rotate(k)
	s[l - 1:r] = list(s2)
print(''.join(s))


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
s = list(si())
n = len(s)
m = ii()
for i in range(m):
	(l, r, k) = mi()
	n1 = r - l + 1
	l -= 1
	k = k % n1
	if k:
		s = s[0:l] + s[r - k:r] + s[l:r - k] + s[r:]
s = ''.join(s)
print(s)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 5)

def rolling(s, n):
	return s[-n % len(s):] + s[:-n % len(s)]

def solve():
	S = list(input())
	N = int(input())
	for _ in range(N):
		(l, r, k) = map(int, input().split())
		t = rolling(S[l - 1:r], k)
		S[l - 1:r] = t
	print(''.join(S))
solve()


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
s = input()
m = vary(1)
for i in range(m):
	(l, r, k) = vary(3)
	st = s[l - 1:r]
	ans = [1] * len(st)
	z = len(st)
	for i in range(len(st)):
		ans[(i + k) % z] = st[i]
	st = ''
	for i in ans:
		st += i
	s = s[:l - 1] + st + s[r:]
print(s)


s = ['*'] + list(input())
for _ in range(int(input())):
	(li, ri, ki) = map(int, input().split())
	ki %= ri - li + 1
	s[li:ri + 1] = s[ri + 1 - ki:ri + 1] + s[li:ri + 1 - ki]
print(*s[1:], sep='')


s = input()
tests = int(input())
for i in range(tests):
	(left, right, k) = map(int, input().split())
	slice = s[left - 1:right]
	k = k % len(slice)
	s = s[:left - 1] + slice[-k:] + slice[:-k] + s[right:]
print(s)


s = list(input())
num_testcases = int(input())
for i in range(num_testcases):
	[l, r, k] = list(map(int, input().split()))
	s_copy = s[l - 1:r]
	for i in range(0, len(s_copy)):
		s[l - 1 + i] = s_copy[(i - k) % (r - l + 1)]
print(''.join(s))


s = input()
for n in range(int(input())):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	if l != r:
		k = k % (r - l + 1)
	b = s[l:r + 1]
	b = b[-k:] + b[:-k]
	s = s[:l] + b + s[r + 1:]
print(s)


s = input()
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	k = k % (r - l + 1)
	t = s[l:r + 1]
	z = t[::-1]
	y = z[:k]
	s = s[0:l] + y[::-1] + t[:r - l + 1 - k] + s[r + 1:]
print(s)


s = input()
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	s1 = s[l - 1:r]
	m = ''
	k = k % (r - l + 1)
	for i in range(r - k, r):
		m += s[i]
	for i in range(l - 1, r - k):
		m += s[i]
	s = s[:l - 1] + m + s[r:]
print(s)


import sys
s = list(sys.stdin.readline())
s2 = list(s)
numQ = int(sys.stdin.readline())
for i in range(numQ):
	ls = sys.stdin.readline().split()
	l = int(ls[0]) - 1
	r = int(ls[1]) - 1
	k = int(ls[2])
	diff = r - l + 1
	for j in range(0, diff):
		newpos = (j + k) % diff + l
		s2[newpos] = s[j + l]
	s = list(s2)
sys.stdout.write(''.join(s2))


s = input()

def rotate(s, a, b, k):
	k %= b - a + 1
	sub = s[a - 1:b]
	return s[:a - 1] + sub[-k:] + sub[:-k] + s[b:]
for _ in range(int(input())):
	s = rotate(s, *map(int, input().split()))
print(s)


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, sin, cos, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000000)
INF = float('inf')
(YES, Yes, yes, NO, No, no) = ('YES', 'Yes', 'yes', 'NO', 'No', 'no')
(dy4, dx4) = ([0, 1, 0, -1], [1, 0, -1, 0])
(dy8, dx8) = ([0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1])

def inside(y, x, H, W):
	return 0 <= y < H and 0 <= x < W

def ceil(a, b):
	return (a + b - 1) // b

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	g = gcd(a, b)
	return a / g * b

def euclidean_distance(y1, x1, y2, x2):
	return sqrt((y1 - y2) ** 2 + (x1 - x2) ** 2)

def manhattan_distance(y1, x1, y2, x2):
	return abs(y1 - y2) + abs(x1 - x2)

def main():
	S = list(input())
	M = int(input())
	for _ in range(M):
		(l, r, k) = map(int, input().split())
		l -= 1
		length = r - l
		k %= length
		t = [0] * length
		p = 0
		for i in range(l, r):
			t[(p + k) % length] = S[i]
			p += 1
		S = S[:l] + t + S[r:]
	print(*S, sep='')
main()


def ans(s, l, r, k):
	if r == len(s):
		subR = ''
	else:
		subR = s[r:len(s)]
	sub = s[l - 1:r]
	subL = s[0:l - 1]
	L = len(sub)
	sub = sub + sub
	sub.replace(' ', '')
	reminder = k % L
	if reminder != 0:
		sub = sub[L - reminder:L - reminder + L]
		s = (subL + sub + subR).replace(' ', '')
		return s
	else:
		return s
s = str(input(''))
n = int(input(''))
for i in range(n):
	(l, r, k) = map(int, input().split(' '))
	s = ans(s, l, r, k)
print(s)


s = list(input())
ls = len(s)
t = [i for i in range(ls)]
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	x = k % (r - l + 1)
	y = r - l + 1 - k % (r - l + 1)
	u = list(t)
	for i in range(l, r + 1):
		if i + x <= r:
			t[i + x] = u[i]
		else:
			t[i - y] = u[i]
ans = [0] * ls
for i in range(ls):
	ans[i] = s[t[i]]
print(''.join(ans))


def rotatestring(s, l, r, k):
	newstring = s[l - 1:r]
	n = r - l + 1
	k = k % n
	newstring = newstring[n - k:] + newstring[:n - k]
	s = s[:l - 1] + newstring + s[r:]
	return s
mystr = input()
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	mystr = rotatestring(mystr, l, r, k)
print(mystr)


string = input()
quantity = int(input())
for i in range(quantity):
	act = input().split()
	start = int(act[0]) - 1
	finish = int(act[1])
	shift = int(act[2])
	subString = string[start:finish]
	shift = shift % len(subString)
	subString = subString[-shift:] + subString[0:-shift]
	string = string[:start] + subString + string[finish:]
print(string)


def rotate(input, d):
	Rfirst = input[0:len(input) - d]
	Rsecond = input[len(input) - d:]
	return Rsecond + Rfirst
s = list(input())
q = int(input())
new_s = s
for i in range(q):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	substring = new_s[l:r + 1]
	k = k % (r - l + 1)
	rotated = rotate(substring, k)
	new_s = new_s[0:l] + rotated + new_s[r + 1:len(s)]
print(''.join(new_s))


s = input()
s = '0' + s
t = int(input())
for tt in range(t):
	(l, r, k) = map(int, input().split())
	k = k % (r - l + 1)
	if k > 0:
		s = s[:l] + s[r - k + 1:r + 1] + s[l:r + 1 - k] + s[r + 1:]
print(s[1:])


def func(string, t):
	if t == 0:
		return string
	return string[-t:] + string[:len(string) - t]
st = input()
q = int(input())
for i in range(q):
	inp = list(map(int, input().split()))
	inp[0] -= 1
	inp[1] -= 1
	if inp[0] == inp[1]:
		continue
	st = st[:inp[0]] + func(st[inp[0]:inp[1] + 1], int(inp[2] % (inp[1] - inp[0] + 1))) + st[inp[1] + 1:]
print(st)


s = input()
n = int(input())
for i in range(n):
	[l, r, k] = list(map(int, input().rstrip().split()))
	l -= 1
	r -= 1
	a = s[l:r + 1]
	b = [a[(i - k) % len(a)] for i in range(len(a))]
	c = ''.join(map(str, b))
	s = s[:l] + c + s[r + 1:]
print(s)


a = input()
i = int(input())
for _ in range(i):
	(x, y, s) = map(int, input().split())
	x -= 1
	y -= 1
	s %= y - x + 1
	if s == 0:
		pass
	else:
		a = a[:x] + a[y - s + 1:y + 1] + a[x:y - s + 1] + a[y + 1:]
print(a)


def rightRotate(lists, num):
	output_list = []
	for item in range(len(lists) - num, len(lists)):
		output_list.append(lists[item])
	for item in range(0, len(lists) - num):
		output_list.append(lists[item])
	return output_list
mainstr = input()
t = int(input())
for _ in range(t):
	(l, r, k) = list(map(int, input().split()))
	tmp = mainstr[l - 1:r]
	LEN = len(tmp)
	rot = k % LEN
	tmp = ''.join([str(elem) for elem in rightRotate(tmp, rot)])
	mainstr = mainstr[:l - 1] + tmp + mainstr[r:]
print(mainstr)


string = input()
n = int(input())
mass = []
for i in range(n):
	mass.append(list(map(int, input().split())))

def shift(a, b, c):
	tmp_str = string[a - 1:b]
	k = c % (b - a + 1)
	join = ''.join
	tmp_str = join([tmp_str[-k:], tmp_str[:-k]])
	return tmp_str
for elem in mass:
	join = ''.join
	string = join([string[:elem[0] - 1], shift(elem[0], elem[1], elem[2]), string[elem[1]:]])
print(string)


s = input()
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split())
	length = r - l + 1
	N = k % length
	s = s[:l - 1] + s[r - N:r] + s[l - 1:r - N] + s[r:]
print(s)


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().rstrip().split())
	k = k % (r - l + 1)
	s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


s = input()
chars = []
nums = {}
s1 = []
s2 = []
for sym in s:
	if not sym in chars:
		nums[sym] = len(chars)
		chars.append(sym)
	s1.append(nums[sym])
	s2.append(nums[sym])
n = int(input())
for i in range(n):
	(a1, a2, k) = map(int, input().split())
	a1 -= 1
	a2 -= 1
	k = k % (a2 - a1 + 1)
	l = a2 - a1 + 1
	for i in range(0, l):
		s2[a1 + (i + k) % l] = s1[a1 + i]
	for i in range(0, l):
		s1[i + a1] = s2[i + a1]
s = ''
for i in range(len(s1)):
	s += chars[s1[i]]
print(s)


from collections import deque
s = input()
string = []
for i in range(len(s)):
	string.append(s[i])
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	k %= r - l + 1
	d = deque()
	for j in range(l, r + 1):
		d.append(string[j])
	d.rotate(k)
	for j in range(l, r + 1):
		string[j] = d[j - l]
print(''.join(string))


s = input()
m = int(input())
from sys import stdin
for i in range(m):
	(l, r, k) = map(int, stdin.readline().split())
	k = k % (r - l + 1)
	s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


s = input()
n = int(input())
pos = [0] * len(s)
for i in range(len(s)):
	pos[i] = i
for i in range(n):
	(l, r, k) = map(int, input().split())
	l -= 1
	k = k % (r - l)
	q = pos[l:r]
	for t in range(r - l):
		pos[l + (t + k) % (r - l)] = q[t]
for i in range(len(s)):
	print(s[pos[i]], end='')


string = input().strip()
m = int(input().strip())
for i in range(m):
	data = input().strip().split()
	data = list(map(int, data))
	(l, r, k) = data
	other = string[l - 1:r]
	k %= r - l + 1
	part = ''
	for i in range(r - l - k + 1, r - l - k + 1 + r - l + 1):
		part += other[i % (r - l + 1)]
	string = string[0:l - 1] + part + string[r:]
print(string)


import sys
from collections import *
import math
input = sys.stdin.readline

def rotate(s, k):
	s = s[::-1]
	x = s[k:][::-1]
	y = s[:k][::-1]
	return y + x
s = input()[:-1]
q = int(input())
while q:
	q -= 1
	(l, r, k) = [int(x) for x in input().split()]
	l -= 1
	x = s[:l]
	y = rotate(s[l:r], k % (r - l))
	z = s[r:]
	s = x + y + z
print(s)


def find(s, c):
	l = len(s)
	return s[-c % l:] + s[:-c % l]
s = input()
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	s = s[:a - 1] + find(s[a - 1:b], c) + s[b:]
print(s)


def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	s = list(input())
	[m] = get()
	for z in range(m):
		[l, r, k] = get()
		l -= 1
		if k > r - l:
			k = k % (r - l)
		temp = s[:l] + s[r - k:r] + s[l:r - k] + s[r:]
		s = temp
	print(''.join(s))
	if mode == 'file':
		f.close()

def __starting_point():
	main()
__starting_point()


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	ch1 = s[:l]
	ch2 = s[r + 1:]
	s1 = s[l:r + 1]
	for j in range(k % (r - l + 1)):
		s2 = ''
		s2 += s1[-1]
		s2 += s1[:-1]
		s1 = s2
	s = ch1 + s1 + ch2
print(s)


import sys
import collections
input = sys.stdin.readline
s = input().strip()
queries = int(input().strip())
for query in range(queries):
	(l, r, k) = map(int, input().strip().split())
	l -= 1
	new_s = []
	old_s = []
	for i in range(l, r):
		new_s += [s[(i + k) % r]]
		old_s += [s[i]]
	for i in range(len(new_s)):
		new_s[(i + k) % len(new_s)] = old_s[i]
	s = s[:l] + ''.join(new_s) + s[r:]
print(s)


s = input()
m = int(input())
for i in range(0, m):
	(l, r, k) = map(int, input().split())
	k = k % (r - l + 1)
	beg = r - k
	if beg != r:
		s = s[:l - 1] + s[beg:r] + s[l - 1:beg] + s[r:]
print(s)


s = list(input())
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().split())
	k = k % (r - l + 1)
	(s[l - 1:l + k - 1], s[l + k - 1:r]) = (s[r - k:r], s[l - 1:r - k])
s = ''.join(s)
print(s)


string = [e for e in input()]
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	k %= r - l + 1
	old_string = string[l:r + 1]
	for j in range(l, r + 1):
		string[j] = old_string[j - l - k]
print(''.join(string))


str = input()
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().strip().split())
	length = r - l + 1
	if length != 1:
		move = k % length
		str = str[:l - 1] + str[r - move:r] + str[l - 1:r - move] + str[r:]
print(str)


word = input()
N = int(input())
query = []
for i in range(N):
	q = input().split()
	query.append(list(map(int, q)))
for q in query:
	(l, r, k) = (q[0] - 1, q[1] - 1, q[2])
	k = k % (r - l + 1)
	if l == r or k == 0:
		continue
	word = word[0:l] + word[r - k + 1:r + 1] + word[l:r - k + 1] + word[r + 1:]
print(word)


a = list(input())
m = int(input())
s = ''
while m > 0:
	(l, r, k) = map(int, input().split())
	d = r - l + 1
	for i in range(d):
		if (i + k) % d == 0:
			a = a[:l - 1] + a[i + l - 1:r] + a[l - 1:i + l - 1] + a[r:]
			break
	m -= 1
print(''.join(a))


temp = [0] * 10000

def shift_cycle(a, left, right, k):
	start = left + k % (right - left + 1)
	for i in range(left, right + 1):
		temp[start] = a[i]
		start = left + (start - left + 1) % (right - left + 1)
	for i in range(left, right + 1):
		a[i] = temp[i]
s = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	shift_cycle(s, l - 1, r - 1, k)
print(''.join(s))


s = list(input())
t = int(input())
while t:
	t = t - 1
	(l, r, k) = map(int, input().split(' '))
	a = s[0:l - 1]
	b = s[l - 1:r]
	c = s[r:]
	x = k % len(b)
	b = b[len(b) - x:] + b[:len(b) - x]
	s = a + b + c
print(''.join(s))


s = input()
for gd in range(int(input())):
	(l, r, k) = map(int, input().split())
	p = r - l + 1
	if p != 0:
		k = k % p
	s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


s = input()
c = int(input()) + 1
for i in range(1, c):
	[l, r, k] = map(int, input().split())
	k %= r - l + 1
	s = s[0:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:len(s)]
print(s)


def shift(s, k):
	k %= len(s)
	return s[-k:] + s[:-k]

def process(s, l, r, k):
	return s[:l - 1] + shift(s[l - 1:r], k) + s[r:]

def __starting_point():
	s = input().strip()
	m = int(input())
	for _ in range(m):
		(l, r, k) = [int(x) for x in input().strip().split()]
		s = process(s, l, r, k)
	print(s)
__starting_point()


s = list(input())
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split())
	k = k % (r - l + 1)
	(s[l - 1:l - 1 + k], s[l - 1 + k:r]) = (s[r - k:r], s[l - 1:r - k])
ans = ''.join(s)
print(ans)


def main():
	from collections import deque
	S = [s for s in input()]
	m = int(input())
	for q in range(m):
		(le, ri, k) = (int(i) for i in input().split())
		k %= ri - le + 1
		d = deque(S[le - 1:ri])
		d.rotate(k)
		S = S[:le - 1] + list(d) + S[ri:]
	print(''.join(S))
main()


string = list(input())
N = int(input())
for i in range(N):
	(l, r, count) = [int(x) for x in input().split(' ')]
	(l, r) = (l - 1, r)
	substr = string[l:r]
	count = count % len(substr)
	moved = [False for _ in range(len(substr))]
	new_substr = [None for _ in range(len(substr))]
	for (ind, chr) in enumerate(substr):
		new_ind = (ind + count) % len(substr)
		new_substr[new_ind] = chr
	string[l:r] = new_substr
print(''.join(string), flush=True)


s = list(input())
m = int(input())
for i in range(m):
	(l1, r1, k1) = map(int, input().split())
	b = s[l1 - 1:r1]
	rem1 = b[:len(b) - k1 % len(b)]
	rem2 = b[len(b) - k1 % len(b):]
	c = [ele for ele in rem2]
	for ele in rem1:
		c.append(ele)
	for j in range(len(c)):
		s[l1 - 1 + j] = c[j]
print(*s, sep='')


s = [c for c in input()]
n = len(s)
m = int(input())
for i in range(m):
	(a, b, k) = map(int, input().split())
	k %= b - a + 1
	s[a - 1:b] = s[b - k:b] + s[a - 1:b - k]
print(''.join(s))


my_string = input().strip()
my_string = list(my_string)
sl = len(my_string)
m = int(input())
for i in range(m):
	(l, r, k) = list(map(int, input().split()))
	range_length = r - l + 1
	k = k % range_length
	l = l - 1
	k = range_length - k
	my_string[l:r] = my_string[l + k:r] + my_string[l:l + k]
ans = ''.join(my_string)
print(ans)


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
s = si()
for _ in range(ii()):
	(l, r, k) = f()
	n = r - l + 1
	x = ''
	for i in range((n - k % n) % n, (n - k % n) % n + n):
		x += s[l - 1 + i % n]
	s = s[:l - 1] + x + s[r:]
print(s)


S = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	ss = S[l - 1:r]
	len_ss = r - (l - 1)
	k %= len_ss
	S[l - 1:r] = ss[-k:] + ss[:-k]
print(''.join(S))


s = input()
a = list(range(len(s)))
m = int(input())
for i in range(m):
	(l, r, k) = [int(j) for j in input().split()]
	l -= 1
	k %= r - l
	a[l:r] = a[r - k:r] + a[l:r - k]
for i in a:
	print(s[i], sep='', end='')
print()


a = list(input())
m = int(input())
s = ''
while m > 0:
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	a = a[:l - 1] + a[r - k:r] + a[l - 1:r - k] + a[r:]
	m -= 1
print(''.join(a))


import sys
from math import floor, sqrt, ceil, factorial, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007

def solve():
	s = input()
	s = [i for i in s]
	q = int(sys.stdin.readline())
	for _ in range(q):
		(l, r, k) = map(int, sys.stdin.readline().split())
		(f, new, a) = (s[:l - 1], s[l - 1:r], s[r:])
		k = k % len(new)
		(new1, new2) = (new[:-k], new[-k:len(new)])
		new = new2 + new1
		s = f + new + a
	print(''.join(s))
solve()


def transformation(s, l, r, k):
	length = len(s)
	length_substring = r - l + 1
	k = k % length_substring
	s = s[0:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:]
	return s
s = input()
m = int(input())
for i in range(m):
	(l_i, r_i, k_i) = map(int, input().split())
	l_i -= 1
	r_i -= 1
	s = transformation(s, l_i, r_i, k_i)
print(s)


from collections import deque
s = list(input())
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split())
	x = deque(s[l - 1:r])
	x.rotate(k)
	s[l - 1:r] = x
print(''.join(map(str, s)))


def move(l, r, k):
	global s
	s = s[:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:]
s = input()
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	k %= r - l + 1
	move(l, r, k)
print(s)


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = [int(x) for x in input().split()]
	start = s[:l - 1]
	middle = s[l - 1:r]
	end = s[r:]
	ln = r - l + 1
	k %= ln
	middle_e = middle[:ln - k]
	middle_s = middle[ln - k:]
	s = start + middle_s + middle_e + end
print(s)


a = str(input())
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split())
	b = a[l - 1:r]
	k %= len(b)
	c = ''
	for j in range(len(b)):
		c += b[j - k]
	c = a[0:l - 1] + c
	if r <= len(a):
		c += a[r:]
	a = c
print(a)


s = input()
s = list(s)
n = len(s)
q = int(input())

def rotate(s, l, r, k):
	s1 = s[:l] + list(s[r - k + 1:r + 1]) + s[l:l + (r - l + 1 - k)] + s[r + 1:]
	return s1
for i in range(q):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	k = k % (r - l + 1)
	s = rotate(s, l, r, k)
print(*s, sep='')


L = [x for x in input()]
m = int(input())
for i in range(m):
	(l, r, k) = [int(x) for x in input().split()]
	l = l - 1
	r = r - 1
	m = r - l + 1
	k = k % m
	temp = L[l:r + 1]
	for i in range(l, r + 1):
		L[i] = temp[i - l - k]
print(''.join(L))


def main():
	s = list(input())
	tmp = [' '] * len(s)
	for _ in range(int(input())):
		(l, r, k) = map(int, input().split())
		l -= 1
		k %= r - l
		if k:
			tmp[l:l + k] = s[r - k:r]
			(s[l:l + k], s[l + k:r]) = (tmp[l:l + k], s[l:r - k])
	print(''.join(s))
main()


n = input()
for i in range(int(input())):
	(l, r, k) = map(int, input().split())
	for j in range(k % (r - l + 1)):
		n = n[:l - 1] + n[r - 1] + n[l - 1:r - 1] + n[r:]
print(n)


import sys
s = input()
for gd in range(int(input())):
	(l, r, k) = map(int, sys.stdin.readline().split())
	p = r - l + 1
	if p != 0:
		k = k % p
	s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


s = input()
m = int(input())
for _ in range(m):
	(l, r, k) = [int(x) for x in input().split()]
	l -= 1
	r -= 1
	k = k % (r - l + 1)
	s = s[:l] + s[r + 1 - k:r + 1] + s[l:r + 1 - k] + s[r + 1:]
print(s)


s = ['1'] + list(input())
m = int(input())
n = len(s) - 1
yy = list(s)
i = 0
while i < m:
	xx = input()
	(l, r, k) = xx.split()
	l = int(l)
	r = int(r)
	k = int(k)
	k = k % (r - l + 1)
	j = l
	ind = ((-k + r - l + 1) % (r - l + 1) + (r - l + 1)) % (r - l + 1)
	while j <= r:
		yy[j] = s[l + ind]
		ind = ind + 1
		if ind >= r - l + 1:
			ind = ind - (r - l + 1)
		j = j + 1
	s = list(yy)
	i = i + 1
i = 1
while i <= n:
	print(s[i], end='')
	i = i + 1
print()


s = input()
for _ in range(int(input())):
	(left, right, k) = [int(x) for x in input().split()]
	left -= 1
	right -= 1
	k = k % (right - left + 1)
	before = s[:left]
	after = s[right + 1:]
	middle = s[right - k + 1:right + 1] + s[left:right - k + 1]
	s = before + middle + after
print(s)


import math
a = input()
t = int(input())
for i in range(t):
	(l, r, k) = list(map(int, input().split()))
	l -= 1
	r -= 1
	k %= r - l + 1
	a = a[:l] + a[r - k + 1:r + 1] + a[l:r - k + 1] + a[r + 1:]
print(a)


s = input()
n = int(input())
for _ in range(n):
	(l, r, k) = [int(i) for i in input().split()]
	k %= r - l + 1
	s = s[:l - 1] + s[r - k:r] + s[l - 1:r - k] + s[r:]
print(s)


w = input()
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	w = w[:l - 1] + w[r - k:r] + w[l - 1:r - k] + w[r:]
print(w)


s = input()
n = int(input())
for i in range(n):
	(l, r, k) = map(int, input().split())
	k %= r - l + 1
	seg = s[l - 1:r]
	seg = seg[len(seg) - k:] + seg[:len(seg) - k]
	s = s[:l - 1] + seg + s[r:]
print(s)


def newString(line, s, f, c):
	subString = line[s:f + 1]
	length = len(subString)
	c = c % length
	if length > 1:
		return line[0:s] + subString[length - c:] + subString[:length - c] + line[f + 1:]
	else:
		return line
string = input()
n = int(input())
for i in range(n):
	(start, end, count) = [int(item) for item in input().split()]
	string = newString(string, start - 1, end - 1, count)
print(string)


def rotate(s, l, r, k):
	size = r - l + 1
	k = k % size
	s = s[0:l] + s[r - k + 1:r + 1] + s[l:r - k + 1] + s[r + 1:len(s)]
	return s
s = input()
for _ in range(int(input())):
	(l, r, k) = map(int, input().split(' '))
	s = rotate(s, l - 1, r - 1, k)
print(s)


s = [ch for ch in input()]
s_len = len(s)
_s = [' '] * s_len
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	l -= 1
	r -= 1
	_len = r - l + 1
	k %= _len
	for x in range(_len):
		_x = (x + k) % _len
		_s[l + _x] = s[l + x]
	for x in range(s_len):
		if _s[x] != ' ':
			s[x] = _s[x]
			_s[x] = ' '
print(''.join(s))


s = input()
testnumber = int(input())
for tn in range(testnumber):
	(l, r, k) = map(int, input().split())
	l -= 1
	n = r - l
	k = k % n
	if k == 0:
		continue
	s = s[:l] + s[r - k:r] + s[l:r - k] + s[r:]
print(s)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	S = list(input().rstrip())
	m = int(input())
	query = [list(map(int, input().split())) for _ in range(m)]
	for (l, r, k) in query:
		n = r - l + 1
		ss = S[l - 1:r]
		new_ss = [''] * n
		for i in range(n):
			new_ss[(i + k) % n] = ss[i]
		S[l - 1:r] = new_ss
	print(''.join(S))
resolve()


S = [c for c in input()]
Q = int(input())
for _ in range(Q):
	(l, r, s) = map(int, input().split())
	length = r - l + 1
	s %= length
	S = S[:l - 1] + S[r - s:r] + S[l - 1:r - s] + S[r:]
print(''.join(S))


from collections import deque
s = input()
v = list(s)
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	kn = k % (r - l + 1)
	d = deque(v[l - 1:r])
	while kn != 0:
		val = d.pop()
		d.appendleft(val)
		kn -= 1
	v[l - 1:r] = list(d)
print(''.join(v))


s = list(input().strip())
q = int(input().strip())
for _ in range(q):
	(l, u, k) = [int(a_temp) for a_temp in input().strip().split()]
	if u == l or not k:
		continue
	k %= u - l + 1
	s = s[:l - 1] + s[u - k:u] + s[l - 1:u - k] + s[u:]
print(''.join(s))


from collections import deque
S = input()
n = int(input())
for _ in range(n):
	data = list(input().split())
	(L, R, K) = (int(data[0]) - 1, int(data[1]), int(data[2]))
	S_Li = list(S)
	sol = deque(S_Li[L:R])
	sol.rotate(K)
	S_Li[L:R] = list(sol)
	S = ''.join(S_Li)
print(''.join(S_Li))


s = input()
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	n = r - l + 1
	(l, k) = (l - 1, k % n)
	sub = s[l:r]
	s = s[:l] + sub[n - k:] + sub[:n - k] + s[r:]
print(s)


s = input()
m = int(input())
for i in range(m):
	(x, y, z) = input().split(' ')
	l = int(x)
	r = int(y)
	k = int(z)
	subs = s[l - 1:r]
	k = k % len(subs)
	newsubs = subs[len(subs) - k:] + subs[0:len(subs) - k]
	s = s[0:l - 1] + newsubs + s[r:]
print(s)


strok = input()
for i in range(int(input())):
	(a, b, c) = [int(i) for i in input().split()]
	q = strok[a - 1:b]
	c = c % (b - a + 1)
	first = b - a + 1 - c
	q = q[first:] + q[:first]
	strok = strok[:a - 1] + q + strok[b:]
print(strok)


s = str(input())
for _ in range(int(input())):
	(l, r, k) = map(int, input().split())
	q = [0] * len(s)
	for i in range(l - 1):
		q[i] = s[i]
	c = r - l + 1
	w = l - 1
	for i in range(c):
		q[l - 1 + (i + k) % c] = s[w]
		w += 1
	for j in range(r, len(s)):
		q[j] = s[j]
	s = ''.join(q)
print(s)


from sys import stdin, stdout

def trace(f):

	def traced(*args, **kw):
		print('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

def f(x):
	print(x)

def read():
	return stdin.readline()[:-1]

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readintarr(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writearr(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)
from collections import deque
from itertools import islice
s = read()
m = readint()
d = deque(s)
for t in range(m):
	(L, R, k) = readintarr()
	(L, R) = (L - 1, R)
	mid = deque(islice(d, L, R))
	mid.rotate(k)
	d = deque(islice(d, 0, L)) + mid + deque(islice(d, R, len(d)))
write(''.join(d))


import logging
import copy
import sys
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

def solve(oriStr, inputLines):
	result = oriStr
	for line in inputLines:
		result = mutation(result, line)
	return result

def mutation(oriStr, inputLines):
	(l, r, k) = (inputLines[0], inputLines[1], inputLines[2])
	preStr = ''
	postStr = ''
	if l > 1:
		preStr = oriStr[:l - 1]
	if r < len(oriStr):
		postStr = oriStr[r:]
	subStr = oriStr[l - 1:r]
	if k > len(subStr):
		k %= len(subStr)
	reStr = subStr[-1 * k:] + subStr[:-1 * k]
	return preStr + reStr + postStr

def main():
	firstLine = input()
	n = int(input())
	inputLines = []
	for i in range(n):
		line = input().split()
		line = list(map(int, line))
		inputLines.append(line)
	print(solve(firstLine, inputLines))

def log(*message):
	logging.debug(message)
main()


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				n = n // i
				cnt += 1
			tmp.append((i, cnt))
	if n > 1:
		tmp.append((n, 1))
	return tmp

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans

def main():
	s = I().strip()
	q = ii()
	for _ in range(q):
		(l, r, k) = mi()
		st = s[:l - 1]
		op = s[l - 1:r]
		end = s[r:]
		for i in range(k % len(op)):
			op = op[-1] + op[:-1]
		s = st + op + end
	print(s)
main()


s = input()
m = int(input())

def rotate(s, l, r, k):
	l -= 1
	k %= r - l
	return s[:l] + s[r - k:r] + s[l:r - k] + s[r:]
for _ in range(m):
	s = rotate(s, *map(int, input().split()))
print(s)


s = list(input())
t = int(input())

def rotate(s, l, r, k):
	k = k % (r - l + 1)
	s[l:r - k + 1] = reversed(s[l:r - k + 1])
	s[r - k + 1:r + 1] = reversed(s[r - k + 1:r + 1])
	s[l:r + 1] = reversed(s[l:r + 1])
for _ in range(t):
	(l, r, k) = map(int, input().split())
	rotate(s, l - 1, r - 1, k)
print(''.join(s))


def cycle(substr, k):
	l = len(substr)
	k %= l
	res = substr[l - k:l] + substr[0:l - k]
	return res
s = list(input())
m = int(input())
for i in range(m):
	(l, r, k) = tuple(map(int, input().split()))
	l -= 1
	r -= 1
	s = s[:l] + cycle(s[l:r + 1], k) + s[r + 1:]
print(''.join(s))


s = input()
for q in range(int(input())):
	(l, r, k) = map(int, input().split())
	if k > r - l + 1:
		k %= r - l + 1
	l -= 1
	r -= 1
	s1 = s[:l]
	s2 = s[r + 1:]
	s3 = s[l:r - k + 1]
	s4 = s[r - k + 1:r + 1]
	s = s1 + s4 + s3 + s2
print(s)


s = input()
m = int(input())
for i in range(m):
	(l, r, k) = [int(x) for x in input().split()]
	k = k % (r - l + 1)
	s1 = s[:l - 1]
	s2 = s[r - k:r]
	s3 = s[l - 1:r - k]
	s4 = s[r:]
	s = s1 + s2 + s3 + s4
print(s)


st = list(input())
m = int(input())
for _ in range(m):
	(l, r, k) = map(int, input().split())
	shift = k % (r - l + 1)
	st = st[:l - 1] + st[r - shift:r] + st[l - 1:r - shift] + st[r:]
print(''.join(st))


s = list(input())
d = len(s)
m = int(input())
for i in range(m):
	(l, r, k) = map(int, input().split())
	x = k % (r - l + 1)
	if x:
		pre = s[l - 1:r - x]
		post = s[r - x:r]
		s[l - 1:r] = post + pre
print(*s, sep='')