Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

mode = 1

def prob_d(s, q):
    ans = s
    for i in range(q):
        ans = ope(ans)
    if mode == -1:
        ans = ans[::-1]
    print(ans)

def reverse():
    global mode
    mode *= -1

def add_head(s, c):
    if mode == -1:
        return s + c
    return c + s

def add_tail(s, c):
    if mode == -1:
        return c + s
    return s + c

def ope(s):
    op = input().split()
    if len(op) == 1 and op[0] == '1':
        reverse()
    elif len(op) == 3 and op[0] == '2':
        if op[1] == "1":
            s = add_head(s, op[2])
        elif op[1] == "2":
            s = add_tail(s, op[2])
        else:
            pass
    else:
        pass
    return s

if __name__ == '__main__':
    s = input()
    q = int(input())
    prob_d(s, q)


Fixed submission:
# -*- coding: utf-8 -*-

from collections import deque as dq

mode = True

def prob_d(s, q):
    ans = dq(s)
    for i in range(q):
        ans = ope(ans)
    if not mode:
        ans = ''.join(list(ans)[::-1])
    else:
        ans = ''.join(ans)
    print(ans)

def ope(s):
    global mode
    op = input().split()
    if len(op) == 1 and op[0] == '1':
        mode = not mode 
    elif len(op) == 3 and op[0] == '2':
        if op[1] == "1":
            if mode:
                s.appendleft(op[2])
            else:
                s.append(op[2])
        elif op[1] == "2":
            if mode:
                s.append(op[2])
            else:
                s.appendleft(op[2])
        else:
            pass
    else:
        pass
    return s

if __name__ == '__main__':
    s = input()
    q = int(input())
    prob_d(s, q)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def prob_d(s, q):
    ans = s
    for i in range(q):
        ans = ope(ans)
    print(ans)

def reverse(s):
    return s[::-1]

def add_head(s, c):
    return c + s

def add_tail(s, c):
    return s + c

def ope(s):
    op = input().split()
    if len(op) == 1 and op[0] == '1':
        s = reverse(s)
    elif len(op) == 3 and op[0] == '2':
        if op[1] == "1":
            s = add_head(s, op[2])
        elif op[1] == "2":
            s = add_tail(s, op[2])
        else:
            pass
    else:
        pass
    return s

if __name__ == '__main__':
    s = input()
    q = int(input())
    prob_d(s, q)


Fixed submission:
# -*- coding: utf-8 -*-

from collections import deque as dq

mode = True

def prob_d(s, q):
    ans = dq(s)
    for i in range(q):
        ans = ope(ans)
    if not mode:
        ans = ''.join(list(ans)[::-1])
    else:
        ans = ''.join(ans)
    print(ans)

def ope(s):
    global mode
    op = input().split()
    if len(op) == 1 and op[0] == '1':
        mode = not mode 
    elif len(op) == 3 and op[0] == '2':
        if op[1] == "1":
            if mode:
                s.appendleft(op[2])
            else:
                s.append(op[2])
        elif op[1] == "2":
            if mode:
                s.append(op[2])
            else:
                s.appendleft(op[2])
        else:
            pass
    else:
        pass
    return s

if __name__ == '__main__':
    s = input()
    q = int(input())
    prob_d(s, q)