Under construction

Still being built. Things may change

Reversal

Interview

Time limit1sMemory limit256 MB

Summary
Apply M substring reversals to a string of up to 2.5 million characters and print the final result.
Level

Easy3 of 10

Topics
String, Implementation, Simulation
Solved
No attempts yet

Problem

A text editor holds a string of NN characters. Mirko performs MM steps. In each step he picks two numbers AA and BB and reverses the substring made of all characters from position AA to position BB, inclusive. To reverse it, he swaps the first character of the substring with the last one, the second with the second to last, and so on. Positions in the string are numbered from 11 to NN.

Write a program that finds the final state of the string after all reversals.

Input

The first line contains the initial string. It consists only of lowercase English letters, and its length NN is at most 2 500 0002\,500\,000. The second line contains a positive integer MM (1≤M≤2 5001 \le M \le 2\,500), the number of steps. Each of the next MM lines contains two positive integers AA and BB (1≤A≤B≤N1 \le A \le B \le N) that describe one step.

Output

Print the string after all reversals on a single line.

Examples2

  1. Example 1

    Input
    lukakuka
    3
    1 4
    5 8
    1 8
    
    Expected output
    kukaluka
    
  2. Example 2

    Input
    kukulelebodumepcele
    5
    3 7
    10 12
    2 10
    5 18
    5 15
    
    Expected output
    kubeeludomepcelluke