跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1492. Queries on a String

    ID: 1498 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟字符串编程与模拟基础难度共享题库Codeforces英文题面题目来源题面语言

Queries on a String

题目描述

B. Queries on a String
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[li... ri] ki 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 l1=3,r1=6,k1=1 then the answer is abbacaa. If after that we would process the query l2=1,r2=4,k2=2 then we would get the string baabcaa.

Input

The first line of the input contains the string s (1≤|s|≤10000) 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 li, ri and ki (1≤liri≤|s|,1≤ki≤1000000)− 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.


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1001 题。保留原作者与原赛事署名。