Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = input()
    if tmp[0] == '1':
        inv = not inv

    else:
        _,f,c = tmp.split()

        if f == '1' and not inv:
            mae += c
        elif f == '2' and not inv:
            usiro += c
        elif f == '1' and inv:
            usiro += c
        elif f == '2' and inv:
            mae += c

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Fixed submission:
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = input()
    if tmp[0] == '1':
        inv = not inv

    else:
        _,f,c = tmp.split()

        if f == '1' and not inv:
            mae += c
        elif f == '2' and not inv:
            usiro += c
        elif f == '1' and inv:
            usiro += c
        elif f == '2' and inv:
            mae += c

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = list(input().split())
    if tmp == ['1']:
        inv = not inv

    elif tmp[1] == '1' and not inv:
        mae += tmp[2]
    elif tmp[1] == '2' and not inv:
        usiro += tmp[2]
    elif tmp[1] == '1' and inv:
        usiro += tmp[2]
    elif tmp[1] == '2' and inv:
        mae += tmp[2]

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Fixed submission:
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = input()
    if tmp[0] == '1':
        inv = not inv

    else:
        _,f,c = tmp.split()

        if f == '1' and not inv:
            mae += c
        elif f == '2' and not inv:
            usiro += c
        elif f == '1' and inv:
            usiro += c
        elif f == '2' and inv:
            mae += c

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = list(input().split())
    if tmp == ['1']:
        inv = not inv

    elif tmp[1] == '1' and not inv:
        mae = mae + tmp[2]
    elif tmp[1] == '2' and not inv:
        usiro = usiro + tmp[2]
    elif tmp[1] == '1' and inv:
        usiro = usiro + tmp[2]
    elif tmp[1] == '2' and inv:
        mae = mae + tmp[2]

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Fixed submission:
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = input()
    if tmp[0] == '1':
        inv = not inv

    else:
        _,f,c = tmp.split()

        if f == '1' and not inv:
            mae += c
        elif f == '2' and not inv:
            usiro += c
        elif f == '1' and inv:
            usiro += c
        elif f == '2' and inv:
            mae += c

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = list(input().split())
    if tmp == ['1']:
        inv = not inv

    elif tmp[1] == '1' and not inv:
        mae = tmp[2] + mae
    elif tmp[1] == '2' and not inv:
        usiro = usiro + tmp[2]
    elif tmp[1] == '1' and inv:
        usiro = usiro + tmp[2]
    elif tmp[1] == '2' and inv:
        mae = tmp[2] + mae

    # print(mae,s,usiro)

ans = mae + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Fixed submission:
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = input()
    if tmp[0] == '1':
        inv = not inv

    else:
        _,f,c = tmp.split()

        if f == '1' and not inv:
            mae += c
        elif f == '2' and not inv:
            usiro += c
        elif f == '1' and inv:
            usiro += c
        elif f == '2' and inv:
            mae += c

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = list(input().split())
    if tmp == ['1']:
        inv = not inv

    elif tmp[1] == '1' and not inv:
        mae = tmp[2] + mae
    elif tmp[1] == '2' and not inv:
        usiro = usiro + tmp[2]
    elif tmp[1] == '1' and inv:
        usiro = usiro + tmp[2]
    elif tmp[1] == '2' and inv:
        mae = tmp[2] + mae

    # print(mae,s,usiro)

ans = ''.join(mae) + s + ''.join(usiro)

if inv:
    ans = ans[::-1]

print(ans)

Fixed submission:
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = input()
    if tmp[0] == '1':
        inv = not inv

    else:
        _,f,c = tmp.split()

        if f == '1' and not inv:
            mae += c
        elif f == '2' and not inv:
            usiro += c
        elif f == '1' and inv:
            usiro += c
        elif f == '2' and inv:
            mae += c

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())


inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = list(input().split())
    if tmp == ['1']:
        inv = not inv

    elif tmp[1] == '1' and not inv:
        mae = tmp[2] + mae
    elif tmp[1] == '2' and not inv:
        usiro = usiro + tmp[2]
    elif tmp[1] == '1' and inv:
        usiro = usiro + tmp[2]
    elif tmp[1] == '2' and inv:
        mae = tmp[2] + mae

    # print(mae,s,usiro)

ans = ''.join(mae) + s + ''.join(usiro)

if inv:
    ans = ans[::-1]

print(ans)

Fixed submission:
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = input()
    if tmp[0] == '1':
        inv = not inv

    else:
        _,f,c = tmp.split()

        if f == '1' and not inv:
            mae += c
        elif f == '2' and not inv:
            usiro += c
        elif f == '1' and inv:
            usiro += c
        elif f == '2' and inv:
            mae += c

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())


inv = False
mae = []
usiro = []

for _ in range(q):
    tmp = list(input().split())
    if tmp == ['1']:
        inv = not inv

    elif tmp[1] == '1' and not inv:
        mae.insert(0,tmp[2])
    elif tmp[1] == '2' and not inv:
        usiro.append(tmp[2])
    elif tmp[1] == '1' and inv:
        usiro.append(tmp[2])
    elif tmp[1] == '2' and inv:
        mae.insert(0,tmp[2])

    # print(mae,s,usiro)

ans = ''.join(mae) + s + ''.join(usiro)

if inv:
    ans = ans[::-1]

print(ans)

Fixed submission:
s = input()
q = int(input())

inv = False
mae = ''
usiro = ''

for _ in range(q):
    tmp = input()
    if tmp[0] == '1':
        inv = not inv

    else:
        _,f,c = tmp.split()

        if f == '1' and not inv:
            mae += c
        elif f == '2' and not inv:
            usiro += c
        elif f == '1' and inv:
            usiro += c
        elif f == '2' and inv:
            mae += c

    # print(mae,s,usiro)

ans = mae[::-1] + s + usiro

if inv:
    ans = ans[::-1]

print(ans)