Buggy python submission (verdict: Runtime Error):
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    l=[]
    l = list(input().split())
    if l[0] == "1":
        x *= -1
    elif l[0] == "2":
        if (l[1] == "2" and x == -1) or  (l[1] == "1" and x == 1):
            S.appendleft(l[2])
        else:
            S.append(l[2])
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Runtime Error):
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    l=[]
    l = list(input().split())
    if l[0] == "1":
        x *= -1
    elif l[0] == "2":
        if (l[1] == "2" and x == -1) or  (l[1] == "1" and x == 1):
            S.appendleft(l[2])
        else:
            S.append(l[2])
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Runtime Error):
xxfrom collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    l=[]
    l = list(input().split())
    if l[0] == "1":
        x *= -1
    elif l[0] == "2":
        if (l[1] == "2" and x == -1) or  (l[1] == "1" and x == 1):
            S.appendleft(0, l[2])
        else:
            S.append(l[2])
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    l=[]
    l = list(input().split())
    if l[0] == "1":
        x *= -1
    elif l[0] == "2":
        if (l[1] == "2" and x == -1) or  (l[1] == "1" and x == 1):
            S.insert(0, l[2])
        else:
            S.append(l[2])
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Runtime Error):
S = list(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    l = list(input().split())
    if l[0] == "1":
        x *= -1
    elif l[0] == "2":
        if (l[1] == "2" and x == -1) or  (l[1] == "1" and x == 1):
            S.insert(0, d)
        else:
            S.append(d)
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Runtime Error):
S = list(input())
Q = int(input())
x = 1
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Runtime Error):
S = list(input())
Q = int(input())
x = 1
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
x = 1
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.insert(0, d)
        else:
            S.append(d)
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
x = 1
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if c == "1":
            if x == -1:
                S.append(d)
            else:
                S.insert(0, d)
        elif c == "2":
            if x == -1:
                S.insert(0, d)
            else:
                S.append(d)
if x == -1:
    S = S[::-1]
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        S = S[::-1]
    elif a == "2":
        c, d = b
        if c == "1":
            S.insert(0, d)
        elif c == "2":
            S.append(d)
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        S = S[::-1]
    else:
        c, d = b
        if c == "1":
            S.insert(0, d)
        else:
            S.append(d)
print(*S, sep="")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")