@staticmethod
def b():
    s = sys.stdin.readline().rstrip()
    (n, *lr) = map(int, sys.stdin.read().split())
    for (l, r) in zip(*([iter(lr)] * 2)):
        l -= 1
        r -= 1
        s = ((s[:l] + s[l:(r + 1)][::(- 1)]) + s[(r + 1):])
    print(s)
@staticmethod
def b():
    s = sys.stdin.readline().rstrip()
    (n, *lr) = map(int, sys.stdin.read().split())
    for (l, r) in zip(*([iter(lr)] * 2)):
        l -= 1
        r -= 1
        s = ((s[:l] + s[l:(r + 1)][::(- 1)]) + s[(r + 1):])
    print(s)