Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = deque(input(""))
Q = int(input())
c = 0

for i in range(Q):
    t = input("")
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c % 2 == 0:
            s.appendleft(t[4])
        else:
            s.append((t[4]))
    else:
        if c % 2 == 0:
            s.append(t[4])
        else:
            s.appendleft(t[4])

if c % 2 == 0:
    for i in s:
        print(i,end="")
else:
    for i in range(len(s)-1,-1,-1):
        print(s[i],end="")



Fixed submission:
s = input("")
Q = int(input())
c = 0
before = []
after = []
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            before.append(t[4])
        else:
            after.append(t[4])
    else:
        if c%2 == 0:
            after.append(t[4])
        else:
            before.append(t[4])

if c%2 == 0:
    print("".join(before[::-1]),end="")
    print(s,end="")
    print("".join(after),end="")
else:
    print("".join(after[::-1]),end="")
    print(s[::-1],end="")
    print("".join(before),end="")

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

s = np.array(list(input("")))
Q = int(input())
c = 0
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            s = np.insert(s,0,t[4])
        else:
            s = np.append(s,t[4])
    else:
        if c%2 == 0:
            s = np.append(s,t[4])
        else:
            s = np.insert(s,0,t[4])

if c%2 == 0:
    for i in range(len(s)):
        print(s[i],end="")
else:
    k = s[::-1]
    for i in range(len(s)):
        print(k[i],end="")

Fixed submission:
s = input("")
Q = int(input())
c = 0
before = []
after = []
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            before.append(t[4])
        else:
            after.append(t[4])
    else:
        if c%2 == 0:
            after.append(t[4])
        else:
            before.append(t[4])

if c%2 == 0:
    print("".join(before[::-1]),end="")
    print(s,end="")
    print("".join(after),end="")
else:
    print("".join(after[::-1]),end="")
    print(s[::-1],end="")
    print("".join(before),end="")

Buggy python submission (verdict: Time Limit Exceeded):
s = input("")
Q = int(input())
c = 0
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            s = t[4] + s
        else:
            s += t[4]
    else:
        if c%2 == 0:
            s += t[4]
        else:
            s = t[4] + s

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

Fixed submission:
s = input("")
Q = int(input())
c = 0
before = []
after = []
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            before.append(t[4])
        else:
            after.append(t[4])
    else:
        if c%2 == 0:
            after.append(t[4])
        else:
            before.append(t[4])

if c%2 == 0:
    print("".join(before[::-1]),end="")
    print(s,end="")
    print("".join(after),end="")
else:
    print("".join(after[::-1]),end="")
    print(s[::-1],end="")
    print("".join(before),end="")

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input(""))
Q = int(input())
c = 0
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            s.insert(0,t[4])
        else:
            s.append(t[4])
    else:
        if c%2 == 0:
            s.append(t[4])
        else:
            s.insert(0,t[4])

if c%2 == 0:
    for i in s:
        print(i,end="")
else:
    for i in s[::-1]:
        print(i,end="")

Fixed submission:
s = input("")
Q = int(input())
c = 0
before = []
after = []
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            before.append(t[4])
        else:
            after.append(t[4])
    else:
        if c%2 == 0:
            after.append(t[4])
        else:
            before.append(t[4])

if c%2 == 0:
    print("".join(before[::-1]),end="")
    print(s,end="")
    print("".join(after),end="")
else:
    print("".join(after[::-1]),end="")
    print(s[::-1],end="")
    print("".join(before),end="")

Buggy python submission (verdict: Time Limit Exceeded):
s = input("")
Q = int(input())
c = 0
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            s = t[4] + s
        else:
            s = s + t[4]
    else:
        if c%2 == 0:
            s = s + t[4]
        else:
            s = t[4] + s

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

Fixed submission:
s = input("")
Q = int(input())
c = 0
before = []
after = []
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            before.append(t[4])
        else:
            after.append(t[4])
    else:
        if c%2 == 0:
            after.append(t[4])
        else:
            before.append(t[4])

if c%2 == 0:
    print("".join(before[::-1]),end="")
    print(s,end="")
    print("".join(after),end="")
else:
    print("".join(after[::-1]),end="")
    print(s[::-1],end="")
    print("".join(before),end="")

Buggy python submission (verdict: Time Limit Exceeded):
s = input("")
Q = int(input())
for i in range(Q):
    t = input()
    if len(t) == 1:
        s = s[::-1]
    elif t[2] == "1":
        s = t[4] + s
    else:
        s = s + t[4]

print(s)

Fixed submission:
s = input("")
Q = int(input())
c = 0
before = []
after = []
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            before.append(t[4])
        else:
            after.append(t[4])
    else:
        if c%2 == 0:
            after.append(t[4])
        else:
            before.append(t[4])

if c%2 == 0:
    print("".join(before[::-1]),end="")
    print(s,end="")
    print("".join(after),end="")
else:
    print("".join(after[::-1]),end="")
    print(s[::-1],end="")
    print("".join(before),end="")

Buggy python submission (verdict: Time Limit Exceeded):
s = input("")
Q = int(input())
for i in range(Q):
    t = input()
    if len(t) == 1:
        s = s[::-1]
    elif t[2] == "1":
        s = t[4] + s
    else:
        s = s + t[4]

print(s)

Fixed submission:
s = input("")
Q = int(input())
c = 0
before = []
after = []
for i in range(Q):
    t = input()
    if len(t) == 1:
        c += 1
    elif t[2] == "1":
        if c%2 == 0:
            before.append(t[4])
        else:
            after.append(t[4])
    else:
        if c%2 == 0:
            after.append(t[4])
        else:
            before.append(t[4])

if c%2 == 0:
    print("".join(before[::-1]),end="")
    print(s,end="")
    print("".join(after),end="")
else:
    print("".join(after[::-1]),end="")
    print(s[::-1],end="")
    print("".join(before),end="")