OKRET - Okret

There is a text consisting of N characters. At each step Mirko chooses two numbers A and B and then reverses the subsequence consisting of characters between indices A and B, inclusive. Indices are 1-based.

Write a program that prints the final text after all operations are made.

Input

The first line of input contains the initial text of length N (1 ≤ N ≤ 2500000). It consists only of lowercase letters of the English alphabet.

The second line contains integer M (1 ≤ M ≤ 2500), the number of steps.

Each of the following M lines contain two integer A and B (1 ≤ A ≤ B ≤ N).

Output

In the first and only line output the final text.

Example

Input: 
lukakuka
3
1 4
5 8
1 8

Output:
kukaluka
Input:
kukulelebodumepcele
5
3 7
10 12
2 10
5 18
5 15

Output:
kubeeludomepcelluke

Added by:Stjepan
Date:2011-05-06
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Croatian Student 2010

hide comments
2022-09-10 08:20:28 Ishan
@prateekk which STL is too slow ?
2012-12-01 19:25:20 Branfili
@kiran
isn't it obvious?
you just switch the chars in the intervals
example 1:
lukakuka
akulkuka
akulakuk
kukaluka
2012-12-21 00:05:28 (Tjandra Satria Gunawan)(曾毅昆)
O(N+M^2)is the best complexity(?) :-D
RE (Buda IM) : is with this constraints, try similar problem TWIST

Last edit: 2012-12-21 00:06:14
2011-06-07 22:16:27 Krzysztof Lewko
@Prateek, because it's too slow
2011-05-24 11:42:12 Prateek Khandelwal
can someone tell me that why it can't be done by just using STL.....using some special functions provided in string library..
2011-05-13 08:03:51 kiran
i want know explanation for the examples ....
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.