Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
for _ in range(q):
    try:
        t,f,c = input().split()
        if f == "1":
            s.insert(0,c)
        else:
            s.append(c)
    except ValueError:
        s = s[::-1]
print(''.join(s))

Fixed submission:
from collections import deque
s = deque(list(input()))
q = int(input())
flg = True
for _ in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == "1":
                s.append(c)
            else:
                s.appendleft(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print(''.join(s))
else:
    s = list(reversed(s))
    print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
l = []
r = []
flg = False
for i in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == '1':
                r.append(c)
            else:
                l.insert(0,c)
        else:
            if f == '1':
                l.insert(0,c)
            else:
                r.append(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print((''.join(r[::-1]))+(s[::-1])+(''.join(l[::-1])))
else:
    print((''.join(l))+(s)+(''.join(r)))

Fixed submission:
from collections import deque
s = deque(list(input()))
q = int(input())
flg = True
for _ in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == "1":
                s.append(c)
            else:
                s.appendleft(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print(''.join(s))
else:
    s = list(reversed(s))
    print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
l = []
r = []
flg = False
for i in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == '1':
                r.append(c)
            else:
                l.insert(0,c)
        else:
            if f == '1':
                l.insert(0,c)
            else:
                r.append(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print((''.join(r[::-1]))+(s[::-1])+(''.join(l[::-1])))
else:
    print((''.join(l))+(s)+(''.join(r)))

Fixed submission:
from collections import deque
s = deque(list(input()))
q = int(input())
flg = True
for _ in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == "1":
                s.append(c)
            else:
                s.appendleft(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print(''.join(s))
else:
    s = list(reversed(s))
    print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
l = []
r = []
flg = False
for i in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == '1':
                r.append(c)
            else:
                l.insert(0,c)
        else:
            if f == '1':
                l.insert(0,c)
            else:
                r.append(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print((''.join(r[::-1]))+(''.join(s[::-1]))+(''.join(l[::-1])))
else:
    print((''.join(l))+(''.join(s))+(''.join(r)))

Fixed submission:
from collections import deque
s = deque(list(input()))
q = int(input())
flg = True
for _ in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == "1":
                s.append(c)
            else:
                s.appendleft(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print(''.join(s))
else:
    s = list(reversed(s))
    print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
flg = False
for i in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == '1':
                s.append(c)
            else:
                s.insert(0,c)
        else:
            if f == '1':
                s.insert(0,c)
            else:
                s.append(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print(''.join(s[::-1]))
else:
    print(''.join(s))

Fixed submission:
from collections import deque
s = deque(list(input()))
q = int(input())
flg = True
for _ in range(q):
    try:
        t,f,c = input().split()
        if flg:
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == "1":
                s.append(c)
            else:
                s.appendleft(c)
    except ValueError:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    print(''.join(s))
else:
    s = list(reversed(s))
    print(''.join(s))