S = raw_input()
N = int(raw_input())
for loop in range(N):
    l,r = map(int,raw_input().split())
    l -= 1; r -= 1
    S = S[:l] + S[l:r+1][::-1] + S[r+1:]
print S

99e84a35d46216772f0cd4d4adf4f2053eb2a3a9
S = raw_input()
N = int(raw_input())
for loop in range(N):
    l,r = map(int,raw_input().split())
    l -= 1; r -= 1
    S = S[:l] + S[l:r+1][::-1] + S[r+1:]
print S
