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

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        s.reverse()
    else:
        if t[1] == "1":
            s.insert(0,t[2])
        else:
            s.append(t[2])

print("".join(s))


Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        s.reverse()
    else:
        if t[1] == "1":
            s.insert(0,t[2])
        else:
            s.append(t[2])

print(*s, sep="")


Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        s = s[::-1]
    else:
        if t[1] == "1":
            s = "".join([t[2],s])
        else:
            s = "".join([s,t[2]])

print(s)


Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

rev = True

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        if rev:
            rev = False
        else:
            rev = True
    else:
        if (t[1] == "1" and rev) or (t[1] == "2" and not rev):
            s = "".join([t[2],s])
        else:
            s = "".join([s,t[2]])

if rev:
    print(s)
else:
    print(s[::-1])


Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

rev = 0

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev += 1
    else:
        if t[1] == "1" and rev % 2 == 0:
            s = "".join([t[2],s])
        elif t[1] == "2" and rev % 2 != 0:
            s = "".join([t[2],s])
        else:
            s = "".join([s,t[2]])

if rev % 2 == 0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        s = s[::-1]
    else:
        if t[1] == "1":
            s = "".join([t[2],s])
        else:
            s = "".join([s,t[2]])

print(s)


Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

rev = 0

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev += 1
    else:
        if (t[1] == "1" and rev % 2 == 0) or (t[1] == "2" and rev % 2 != 0):
            s = "".join([t[2],s])
        else:
            s = "".join([s,t[2]])

if rev % 2 == 0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

rev = 0

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev += 1
    else:
        if (t[1] == "1" and rev % 2 == 0) or (t[1] == "2" and rev % 2 != 0):
            tmp = [t[2],s]
            s = "".join(tmp)
        else:
            tmp = [s,t[2]]
            s = "".join(tmp)

if rev % 2 == 0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

rev = 0

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev += 1
    else:
        if (t[1] == "1" and rev % 2 == 0) or (t[1] == "2" and rev % 2 != 0):
            s = t[2] + s
        else:
            s += t[2]

if rev % 2 == 0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        s = s[::-1]
    else:
        if t[1] == "1":
            s = t[2] + s
        else:
            s += t[2]

print(s)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))

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

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        s = s[::-1]
    else:
        if t[1] == "1":
            s = t[2] + s
        else:
            s = s + t[2]

print(s)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

rev = False

for _ in range(q):
    t = [x for x in input().split()]
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            s.append(t[2]) if rev else s.appendleft(t[2])
        else:
            s.appendleft(t[2]) if rev else s.append(t[2])

if rev:
    s.reverse()
print("".join(s))