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

roll = False
ans = [s]
preNum = 0

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(ans)
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            ans = ans[::-1]
            #print(ans, 'rev')
            ans.append(c)
            #print(ans, '+C')
            ans = ans[::-1]
            #print(ans, 'ver')
            preNum += 1
        else :
            ans.append(c)
#print(ans)
if roll :
    ans[preNum] = ans [preNum][::-1]
    ans = ans[::-1]

#print(ans)
#print("".join(ans))
for s in ans :
    print(s, end='')


Fixed submission:
from collections import deque

s = input()
q = int(input())

roll = False
ans = deque([s])
preNum = 0

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(ans)
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            ans.appendleft(c)
            preNum += 1
        else :
            ans.append(c)
#print(ans)
ans = list(ans)
if roll :
    ans[preNum] = ans[preNum][::-1]
    ans = ans[::-1]

#print(ans)
#print("".join(ans))
for s in ans :
    print(s, end='')

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

roll = False
ans = [s]
preNum = 0

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(ans)
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            ans = ans[::-1]
            #print(ans, 'rev')
            ans.append(c)
            #print(ans, '+C')
            ans = ans[::-1]
            #print(ans, 'ver')
            preNum += 1
        else :
            ans.append(c)
#print(ans)
if roll :
    ans[preNum] = ans [preNum][::-1]
    ans = ans[::-1]

#print(ans)

print("".join(ans))


Fixed submission:
from collections import deque

s = input()
q = int(input())

roll = False
ans = deque([s])
preNum = 0

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(ans)
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            ans.appendleft(c)
            preNum += 1
        else :
            ans.append(c)
#print(ans)
ans = list(ans)
if roll :
    ans[preNum] = ans[preNum][::-1]
    ans = ans[::-1]

#print(ans)
#print("".join(ans))
for s in ans :
    print(s, end='')

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

roll = False

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            s = "{}{}".format(c, s)
        else :
            s = "{}{}".format(s, c)

if roll :
    s = s[::-1]

print(s)


Fixed submission:
from collections import deque

s = input()
q = int(input())

roll = False
ans = deque([s])
preNum = 0

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(ans)
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            ans.appendleft(c)
            preNum += 1
        else :
            ans.append(c)
#print(ans)
ans = list(ans)
if roll :
    ans[preNum] = ans[preNum][::-1]
    ans = ans[::-1]

#print(ans)
#print("".join(ans))
for s in ans :
    print(s, end='')

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

roll = False

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            s = c + s
        else :
            s += c

if roll :
    s = s[::-1]

print(s)


Fixed submission:
from collections import deque

s = input()
q = int(input())

roll = False
ans = deque([s])
preNum = 0

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(ans)
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            ans.appendleft(c)
            preNum += 1
        else :
            ans.append(c)
#print(ans)
ans = list(ans)
if roll :
    ans[preNum] = ans[preNum][::-1]
    ans = ans[::-1]

#print(ans)
#print("".join(ans))
for s in ans :
    print(s, end='')