Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
A =input()
S = deque(A)
H = 1
Q = int(input())
Qlist = []
for i in range(Q):
    op = list((map(str,input().split())))
    if len(op) ==1:
        H *= -1
    else:
        if op[1] =='1':
            if H == 1:
                S.appendleft(op[2])
            else:
                S.append(op[2]) 
        else:
            if H == 1:
                S.append(op[2])
            else:
                S.appendleft(op[2])
if H == -1:
    A = S[-1]
    for i in range(1,len(S)):
        A += S[-i-1]
else:
    A = S[0]
    for i in range(1,len(S)):
        A += S[i]
print(A)

Fixed submission:
from collections import deque
S= deque(input())
Q = int(input())
ba = 1
for i in range(Q):
    Query =list(map(str,input().split()))
    Query0 = Query[0]
    if Query[0] == '1':
        ba *= -1
    else:
        if Query[1] == '1' and ba ==1:
            S.appendleft(Query[2])
        elif Query[1] == '1' and ba ==-1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==-1:
            S.appendleft(Query[2])
if ba == -1:
    S.reverse()
mojieru = ''.join(S)
print(mojieru)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
A =input()
S = deque(A)
H = 0
Q = int(input())
Qlist = []
for i in range(Q):
    op = list((map(str,input().split())))
    if len(op) ==1:
        H +=1
    else:
        if op[1] =='1':
            if H%2 == 0:
                S.appendleft(op[2])
            else:
                S.append(op[2]) 
        else:
            if H%2 == 0:
                S.append(op[2])
            else:
                S.appendleft(op[2])
if H%2 == 1:
    A = S[-1]
    for i in range(1,len(S)):
        A += S[-i-1]
else:
    A = S[0]
    for i in range(1,len(S)):
        A += S[i]
print(A)

Fixed submission:
from collections import deque
S= deque(input())
Q = int(input())
ba = 1
for i in range(Q):
    Query =list(map(str,input().split()))
    Query0 = Query[0]
    if Query[0] == '1':
        ba *= -1
    else:
        if Query[1] == '1' and ba ==1:
            S.appendleft(Query[2])
        elif Query[1] == '1' and ba ==-1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==-1:
            S.appendleft(Query[2])
if ba == -1:
    S.reverse()
mojieru = ''.join(S)
print(mojieru)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
A =input()
S = deque(A)
H = 0
Q = int(input())
Qlist = []
for i in range(Q):
    Qlist.append(list((map(str,input().split()))))
for i in range(Q):
    op = Qlist[i]
    if len(op) ==1:
        H +=1
    else:
        if op[1] =='1':
            if H%2 == 0:
                S.appendleft(op[2])
            else:
                S.append(op[2]) 
        else:
            if H%2 == 0:
                S.append(op[2])
            else:
                S.appendleft(op[2])
if H%2 == 1:
    A = S[-1]
    for i in range(1,len(S)):
        A += S[-i-1]
else:
    A = S[0]
    for i in range(1,len(S)):
        A += S[i]
print(A)

Fixed submission:
from collections import deque
S= deque(input())
Q = int(input())
ba = 1
for i in range(Q):
    Query =list(map(str,input().split()))
    Query0 = Query[0]
    if Query[0] == '1':
        ba *= -1
    else:
        if Query[1] == '1' and ba ==1:
            S.appendleft(Query[2])
        elif Query[1] == '1' and ba ==-1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==-1:
            S.appendleft(Query[2])
if ba == -1:
    S.reverse()
mojieru = ''.join(S)
print(mojieru)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
A =input()
S = deque(A)
H = 0
Q = int(input())
Qlist = []
for i in range(Q):
    Qlist.append(list((map(str,input().split()))))
for i in range(Q):
    op = Qlist[i]
    if len(op) ==1:
        H +=1
    else:
        if op[1] =='1':
            if H%2 == 0:
                S.appendleft(op[2])
            else:
                S.append(op[2]) 
        else:
            if H%2 == 0:
                S.append(op[2])
            else:
                S.appendleft(op[2])
if H%2 == 1:
    S.reverse()
A = S[0]
for i in range(1,len(S)):
    A += S[i]
print(A)

Fixed submission:
from collections import deque
S= deque(input())
Q = int(input())
ba = 1
for i in range(Q):
    Query =list(map(str,input().split()))
    Query0 = Query[0]
    if Query[0] == '1':
        ba *= -1
    else:
        if Query[1] == '1' and ba ==1:
            S.appendleft(Query[2])
        elif Query[1] == '1' and ba ==-1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==-1:
            S.appendleft(Query[2])
if ba == -1:
    S.reverse()
mojieru = ''.join(S)
print(mojieru)

Buggy python submission (verdict: Time Limit Exceeded):
A =input()
S = list(A)
Q = int(input())
Qlist = []
for i in range(Q):
    Qlist.append(list((map(str,input().split()))))
for i in range(Q):
    op = Qlist[i]
    if len(op) ==1:
        S.reverse()
    else:
        if op[1] =='1':
            S.reverse()
            S.append(op[2])
            S.reverse()
        else:
            S.append(op[2])
A = S[0]
for i in range(1,len(S)):
    A += S[i]
print(A)

Fixed submission:
from collections import deque
S= deque(input())
Q = int(input())
ba = 1
for i in range(Q):
    Query =list(map(str,input().split()))
    Query0 = Query[0]
    if Query[0] == '1':
        ba *= -1
    else:
        if Query[1] == '1' and ba ==1:
            S.appendleft(Query[2])
        elif Query[1] == '1' and ba ==-1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==-1:
            S.appendleft(Query[2])
if ba == -1:
    S.reverse()
mojieru = ''.join(S)
print(mojieru)