11244 - Flip   

Description

The input contains a string and K pairs of integers. Each pair contains two integers N and M. The operation is to flip the order of M characters that begins at the N-th position of the input string.

For example, consider the input string "SRVisHandsome", and the pair N = 3, M = 5. The character at position 3 is 'V' and the following 5 characters are "VisHa". Hence you have to flip the 5 characters into "aHsiV", and thus the string becomes "SRaHsiVndsome". Note that the input string contains no more than 1000 characters, and N+M-1 will not exceed the length of the string. A full example: If the input is
ABCDEFGH
3
3 5
5 4
2 6

The string will be changed as follows: ABGFEDCH => ABGFHCDE  =>  ADCHFGBE

Input

The first line is the input string. The second line is an integer K indicating there are K pairs of integers in the following K lines. Each pair of integers N and M represents the position of the starting character and the number of characters to be flipped.

Output

Print the final string after K rounds of flipping.

Sample Input  Download

Sample Output  Download

Tags




Discuss