Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

S_normal = S
S_inverse = S[::-1]
for q in range(Q):
    tmp1 = []
    tmp2 = []
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        S = S_inverse
        S_inverse = S_normal
        S_normal = S
    else:
        if int(query[1]) == 1:
            tmp1.append(query[2])
            tmp1.append(S)
            S = ''.join(tmp1)
            S_normal = S
            tmp2.append(S_inverse)
            tmp2.append(query[2])
            S_inverse = ''.join(tmp2)
        else:
            tmp2.append(S)
            tmp2.append(query[2])
            S = ''.join(tmp2)
            S_normal = S
            tmp1.append(query[2])
            tmp1.append(S_inverse)
            S_inverse = ''.join(tmp1)

print(S)

Fixed submission:
from collections import deque

S = str(input())
Q = int(input())

d = deque(list(S))

rev = False

for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if int(query[1]) == 1:
            if not rev:
                d.appendleft(query[2])
            else:
                d.append(query[2])
        else:
            if not rev:
                d.append(query[2])
            else:
                d.appendleft(query[2])

if rev:
    print(''.join(d)[::-1])
else:
    print(''.join(d))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

for q in range(Q):
    query = list(map(str, input().split()))
    tmp = []
    if int(query[0]) == 1:
        S = S[::-1]
    else:
        if int(query[1]) == 1:
            tmp.append(query[2])
            tmp.append(S)
            S = ''.join(tmp)
        else:
            tmp.append(S)
            tmp.append(query[2])
            S = ''.join(tmp)

print(S)

Fixed submission:
from collections import deque

S = str(input())
Q = int(input())

d = deque(list(S))

rev = False

for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if int(query[1]) == 1:
            if not rev:
                d.appendleft(query[2])
            else:
                d.append(query[2])
        else:
            if not rev:
                d.append(query[2])
            else:
                d.appendleft(query[2])

if rev:
    print(''.join(d)[::-1])
else:
    print(''.join(d))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

S_normal = S
S_inverse = S[::-1]
for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        S = S_inverse
        S_inverse = S_normal
        S_normal = S
    else:
        if int(query[1]) == 1:
            S = query[2]+S
            S_normal = S
            S_inverse += query[2]
        else:
            S += query[2]
            S_normal = S
            S_inverse = query[2]+S_inverse

print(S)

Fixed submission:
from collections import deque

S = str(input())
Q = int(input())

d = deque(list(S))

rev = False

for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if int(query[1]) == 1:
            if not rev:
                d.appendleft(query[2])
            else:
                d.append(query[2])
        else:
            if not rev:
                d.append(query[2])
            else:
                d.appendleft(query[2])

if rev:
    print(''.join(d)[::-1])
else:
    print(''.join(d))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

S_normal = S
S_inverse = S[::-1]
for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        S = S_inverse
        S_inverse = S_normal
        S_normal = S
    else:
        if int(query[1]) == 1:
            S = query[2]+S
            S_normal = S
            S_inverse += query[2]
        else:
            S += query[2]
            S_normal = S
            S_inverse = query[2]+S_inverse

print(S)

Fixed submission:
from collections import deque

S = str(input())
Q = int(input())

d = deque(list(S))

rev = False

for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if int(query[1]) == 1:
            if not rev:
                d.appendleft(query[2])
            else:
                d.append(query[2])
        else:
            if not rev:
                d.append(query[2])
            else:
                d.appendleft(query[2])

if rev:
    print(''.join(d)[::-1])
else:
    print(''.join(d))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        S = S[::-1]
    else:
        if int(query[1]) == 1:
            S = query[2]+S
        else:
            S += query[2]

print(S)

Fixed submission:
from collections import deque

S = str(input())
Q = int(input())

d = deque(list(S))

rev = False

for q in range(Q):
    query = list(map(str, input().split()))
    if int(query[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if int(query[1]) == 1:
            if not rev:
                d.appendleft(query[2])
            else:
                d.append(query[2])
        else:
            if not rev:
                d.append(query[2])
            else:
                d.appendleft(query[2])

if rev:
    print(''.join(d)[::-1])
else:
    print(''.join(d))