Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
tmp = s
flag = 0
for _ in range(q):
    _s = input()
    if _s == "1":
        flag += 1
    else:
        f = _s[2]
        c = _s[4]
        r = flag % 2
        if f == "1" and r == 0:
            tmp = c + tmp
        elif f == "1" and r == 1:
            tmp = tmp + c
        elif f == "2" and r == 0:
            tmp = tmp + c
        elif f == "2" and r == 1:
            tmp = c + tmp
if flag % 2 == 0:
    print(tmp)
else:
    print(tmp[::-1])

Fixed submission:
from collections import deque
s = input()
q = int(input())
tmp = deque()
for i in range(len(s)):
    tmp.append(s[i])
flag = 0
for _ in range(q):
    _s = input()
    if _s == "1":
        flag += 1
    else:
        t, f, c = _s.split(" ")
        r = flag % 2
        if f == "1" and r == 0:
            #tmp = c + tmp
            tmp.appendleft(c)
        elif f == "1" and r == 1:
            #tmp = tmp + c
            tmp.append(c)
        elif f == "2" and r == 0:
            #tmp = tmp + c
            tmp.append(c)
        elif f == "2" and r == 1:
            #tmp = c + tmp
            tmp.appendleft(c)
if flag % 2 == 0:
    for i in range(len(tmp)):
        print(tmp.popleft(), end="")
else:
    for i in range(len(tmp)):
        print(tmp.pop(), end="")

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
tmp = s
flag = 0
for _ in range(q):
    _s = input()
    t = 0
    f = 0
    c = ""
    if _s == "1":
        flag += 1
    else:
        t, f, c = _s.split(" ")
        r = flag % 2
        if f == "1" and r == 0:
            tmp = c + tmp
        elif f == "1" and r == 1:
            tmp = tmp + c
        elif f == "2" and r == 0:
            tmp = tmp + c
        elif f == "2" and r == 1:
            tmp = c + tmp
if flag % 2 == 0:
    print(tmp)
else:
    print(tmp[::-1])
        

Fixed submission:
from collections import deque
s = input()
q = int(input())
tmp = deque()
for i in range(len(s)):
    tmp.append(s[i])
flag = 0
for _ in range(q):
    _s = input()
    if _s == "1":
        flag += 1
    else:
        t, f, c = _s.split(" ")
        r = flag % 2
        if f == "1" and r == 0:
            #tmp = c + tmp
            tmp.appendleft(c)
        elif f == "1" and r == 1:
            #tmp = tmp + c
            tmp.append(c)
        elif f == "2" and r == 0:
            #tmp = tmp + c
            tmp.append(c)
        elif f == "2" and r == 1:
            #tmp = c + tmp
            tmp.appendleft(c)
if flag % 2 == 0:
    for i in range(len(tmp)):
        print(tmp.popleft(), end="")
else:
    for i in range(len(tmp)):
        print(tmp.pop(), end="")

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
tmp = s
flag = 0
for _ in range(q):
    _s = input()
    t = 0
    f = 0
    c = ""
    if _s == "1":
        flag += 1
    else:
        t, f, c = _s.split(" ")
        if f == "1" and flag % 2 == 0:
            tmp = c + tmp
        elif f == "1" and flag % 2 == 1:
            tmp = tmp + c
        elif f == "2" and flag % 2 == 0:
            tmp = tmp + c
        elif f == "2" and flag % 2 == 1:
            tmp = c + tmp
if flag % 2 == 0:
    print(tmp)
else:
    print(tmp[::-1])
        

Fixed submission:
from collections import deque
s = input()
q = int(input())
tmp = deque()
for i in range(len(s)):
    tmp.append(s[i])
flag = 0
for _ in range(q):
    _s = input()
    if _s == "1":
        flag += 1
    else:
        t, f, c = _s.split(" ")
        r = flag % 2
        if f == "1" and r == 0:
            #tmp = c + tmp
            tmp.appendleft(c)
        elif f == "1" and r == 1:
            #tmp = tmp + c
            tmp.append(c)
        elif f == "2" and r == 0:
            #tmp = tmp + c
            tmp.append(c)
        elif f == "2" and r == 1:
            #tmp = c + tmp
            tmp.appendleft(c)
if flag % 2 == 0:
    for i in range(len(tmp)):
        print(tmp.popleft(), end="")
else:
    for i in range(len(tmp)):
        print(tmp.pop(), end="")

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
tmp = s
for _ in range(q):
    _s = input()
    t = 0
    f = 0
    c = ""
    if _s == "1":
        tmp = tmp[::-1]
    else:
        t, f, c = _s.split(" ")
        if f == "1":
            tmp = c + tmp
        else:
            tmp = tmp + c
print(tmp)
        

Fixed submission:
from collections import deque
s = input()
q = int(input())
tmp = deque()
for i in range(len(s)):
    tmp.append(s[i])
flag = 0
for _ in range(q):
    _s = input()
    if _s == "1":
        flag += 1
    else:
        t, f, c = _s.split(" ")
        r = flag % 2
        if f == "1" and r == 0:
            #tmp = c + tmp
            tmp.appendleft(c)
        elif f == "1" and r == 1:
            #tmp = tmp + c
            tmp.append(c)
        elif f == "2" and r == 0:
            #tmp = tmp + c
            tmp.append(c)
        elif f == "2" and r == 1:
            #tmp = c + tmp
            tmp.appendleft(c)
if flag % 2 == 0:
    for i in range(len(tmp)):
        print(tmp.popleft(), end="")
else:
    for i in range(len(tmp)):
        print(tmp.pop(), end="")