Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
S = input()
Q = int(input())
#S = "a"*100000
#Q = 200000
pre = ""
suf = ""

rev = 0
for i in range(Q):
    q = input().split()
    '''
    if i % 3 == 0:
        q = ('1')
    if i % 3 == 1:
        q = (2,'1','b')
    if i % 3 == 2:
        q = (2,'2','b')
        '''

    if len(q) == 1:
        rev = (rev + 1) % 2
    else:
        _, f, c = q
        f = f.decode()
        c = c.decode()
        if f == '1':
            if rev == 0:
                pre += c
            else:
                suf += c
        else:
            if rev == 0:
                suf += c
            else:
                pre += c

S = S.decode()[:-1]
ans = pre[::-1] + S + suf
if rev == 0:
    print(ans)
else:
    print(ans[::-1])


Fixed submission:
import sys
input = sys.stdin.buffer.readline
S = input()
Q = int(input())
#S = "a"*100000
#Q = 200000
pre = ""
suf = ""

rev = 0
for i in range(Q):
    q = input().split()
    '''
    if i % 3 == 0:
        q = ('1')
    if i % 3 == 1:
        q = (2,'1','b')
    if i % 3 == 2:
        q = (2,'2','b')
        '''

    if len(q) == 1:
        rev = (rev + 1) % 2
    else:
        _, f, c = q
        f = f.decode()
        c = c.decode()
        if f == '1':
            if rev == 0:
                pre += c
            else:
                suf += c
        else:
            if rev == 0:
                suf += c
            else:
                pre += c

S = S.decode()[:-1]
ans = pre[::-1] + S + suf
if rev == 0:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
Q = int(input())

pre = ""
suf = ""

rev = 0
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        rev = (rev + 1) % 2
    else:
        _, f, c = q
        if f == '1':
            if rev == 0:
                pre += c
            else:
                suf += c
        else:
            if rev == 0:
                suf += c
            else:
                pre += c


ans = pre[::-1] + S + suf
if rev == 0:
    print(ans)
else:
    print(ans[::-1])


Fixed submission:
import sys
input = sys.stdin.buffer.readline
S = input()
Q = int(input())
#S = "a"*100000
#Q = 200000
pre = ""
suf = ""

rev = 0
for i in range(Q):
    q = input().split()
    '''
    if i % 3 == 0:
        q = ('1')
    if i % 3 == 1:
        q = (2,'1','b')
    if i % 3 == 2:
        q = (2,'2','b')
        '''

    if len(q) == 1:
        rev = (rev + 1) % 2
    else:
        _, f, c = q
        f = f.decode()
        c = c.decode()
        if f == '1':
            if rev == 0:
                pre += c
            else:
                suf += c
        else:
            if rev == 0:
                suf += c
            else:
                pre += c

S = S.decode()[:-1]
ans = pre[::-1] + S + suf
if rev == 0:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

pre = ""
suf = "" 
rev = 0
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        rev = (rev + 1) % 2
    else:
        _, f, c = q
        if f == '1':
            if rev == 0:
                pre = c + pre
            else:
                suf = suf + c
        else:
            if rev == 0:
                suf = suf + c
            else:
                pre = c + pre

ans = pre + S + suf
if rev == 0:
    print(ans)
else:
    print(ans[::-1])


Fixed submission:
import sys
input = sys.stdin.buffer.readline
S = input()
Q = int(input())
#S = "a"*100000
#Q = 200000
pre = ""
suf = ""

rev = 0
for i in range(Q):
    q = input().split()
    '''
    if i % 3 == 0:
        q = ('1')
    if i % 3 == 1:
        q = (2,'1','b')
    if i % 3 == 2:
        q = (2,'2','b')
        '''

    if len(q) == 1:
        rev = (rev + 1) % 2
    else:
        _, f, c = q
        f = f.decode()
        c = c.decode()
        if f == '1':
            if rev == 0:
                pre += c
            else:
                suf += c
        else:
            if rev == 0:
                suf += c
            else:
                pre += c

S = S.decode()[:-1]
ans = pre[::-1] + S + suf
if rev == 0:
    print(ans)
else:
    print(ans[::-1])