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

a = ['']*n
def rev(t):
    m = len(t)
    b = ['']*m
    for j in range(m):
        b[j] = t[m-j-1]
    c = ''
    for k in range(len(b)):
        c += b[k]
    return c

for i in range(n):
    a[i] = input()
    if a[i] == '1':
        s = rev(s)
    else:
        p,q,r = list(a[i].split())
        if q == '1':
            s = r+s
        else:
            s = s+r
print(s)


Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())
t = 0
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        t += 1
    else:
        query[1] = int(query[1])
        if t % 2 == 1:
            if query[1] == 1:
                query[1] = 2
            else:
                query[1] = 1
        if query[1] == 1:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if t % 2 == 1:
    S.reverse()
print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
t = 0
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        t += 1
    else:
        query[1] = int(query[1])
        if t % 2 == 1:
            if query[1] == 1:
                query[1] = 2
            else:
                query[1] = 1
        if query[1] == 1:
            S.insert(0, query[2])
        else:
            S.append(query[2])
if t % 2 == 1:
    S.reverse()
print("".join(S))


Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())
t = 0
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        t += 1
    else:
        query[1] = int(query[1])
        if t % 2 == 1:
            if query[1] == 1:
                query[1] = 2
            else:
                query[1] = 1
        if query[1] == 1:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if t % 2 == 1:
    S.reverse()
print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S.reverse()
    else:
        if int(query[1]) == 1:
            S.insert(0, query[2])
        else:
            S.append(query[2])
print("".join(S))

Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())
t = 0
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        t += 1
    else:
        query[1] = int(query[1])
        if t % 2 == 1:
            if query[1] == 1:
                query[1] = 2
            else:
                query[1] = 1
        if query[1] == 1:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if t % 2 == 1:
    S.reverse()
print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S.reverse()
    else:
        if int(query[1]) == 1:
            S.insert(0, query[2])
        else:
            S.append(query[2])
print("".join(S))


Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())
t = 0
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        t += 1
    else:
        query[1] = int(query[1])
        if t % 2 == 1:
            if query[1] == 1:
                query[1] = 2
            else:
                query[1] = 1
        if query[1] == 1:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if t % 2 == 1:
    S.reverse()
print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S.reverse()
    else:
        if int(query[1]) == 1:
            S = list("{0}{1}".format(query[2], "".join(S)))
        else:
            S = list("{0}{1}".format("".join(S), query[2]))
print("".join(S))


Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())
t = 0
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        t += 1
    else:
        query[1] = int(query[1])
        if t % 2 == 1:
            if query[1] == 1:
                query[1] = 2
            else:
                query[1] = 1
        if query[1] == 1:
            S.appendleft(query[2])
        else:
            S.append(query[2])
if t % 2 == 1:
    S.reverse()
print("".join(S))