Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
cou = 1
frt = ""
bck = ""
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if (t[1] == "1" and cou == 1)or(t[1] == "2" and cou == -1):
            s = t[2] + s
        else:
            s = s + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

#s = frt + s + bck
#logging.debug(s)#
if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Fixed submission:
s = input()
q = int(input())
cou = 1
frt = ""
bck = ""
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if (t[1] == "1" and cou == 1)or(t[1] == "2" and cou == -1):
            frt = t[2] + frt
        else:
            bck = bck + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

s = frt + s + bck
#logging.debug(s)#
if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
cou = 1
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if t[1] == "1" and cou == 1:
            s = t[2] + s
        elif t[1] == "2" and cou == -1:
            s = t[2] + s
        else:
            s = s + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Fixed submission:
s = input()
q = int(input())
cou = 1
frt = ""
bck = ""
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if (t[1] == "1" and cou == 1)or(t[1] == "2" and cou == -1):
            frt = t[2] + frt
        else:
            bck = bck + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

s = frt + s + bck
#logging.debug(s)#
if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
cou = 1
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if t[1] == "1" and cou == 1:
            s = t[2] + s
        elif t[1] == "2" and cou == -1:
            s = t[2] + s
        else:
            s = s + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Fixed submission:
s = input()
q = int(input())
cou = 1
frt = ""
bck = ""
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if (t[1] == "1" and cou == 1)or(t[1] == "2" and cou == -1):
            frt = t[2] + frt
        else:
            bck = bck + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

s = frt + s + bck
#logging.debug(s)#
if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()  #文字
Q = int(input())  #数字
X = [0] * Q
R = 1
for i in range(Q):
    X[i] = list(input().split() ) #文字、複数行複数列
    if X[i][0] == "1":
        R *= - 1
    else:
        T = int(X[i][1])
        if T * R == 1 or T * R == -2:
            S = X[i][2] + S
        else:
            S = S + X[i][2]                

print(S[::R])

Fixed submission:
s = input()
q = int(input())
cou = 1
frt = ""
bck = ""
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if (t[1] == "1" and cou == 1)or(t[1] == "2" and cou == -1):
            frt = t[2] + frt
        else:
            bck = bck + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

s = frt + s + bck
#logging.debug(s)#
if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()  #文字
Q = int(input())  #数字
X = [0] * Q
R = 1
for i in range(Q):
    X[i] = list(input().split() ) #文字、複数行複数列
    if X[i][0] == "1":
        R *= - 1
    else:
        if X[i][1] == "1":
            if R == 1:
                S = X[i][2] + S
            else:
                S = S + X[i][2]                
        else:
            if R == 1:
                S = S + X[i][2]                
            else:
                S = X[i][2] + S

print(S[::R])

Fixed submission:
s = input()
q = int(input())
cou = 1
frt = ""
bck = ""
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if (t[1] == "1" and cou == 1)or(t[1] == "2" and cou == -1):
            frt = t[2] + frt
        else:
            bck = bck + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

s = frt + s + bck
#logging.debug(s)#
if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()  #文字
Q = int(input())  #数字
X = [0] * Q
for i in range(Q):
    X[i] = list(input().split() ) #文字、複数行複数列
    if X[i][0] == "1":        
        S = S[::-1]
    else:
        if X[i][1] == "1":
            S = X[i][2] + S
        else:
            S = S + X[i][2]
print(S)

Fixed submission:
s = input()
q = int(input())
cou = 1
frt = ""
bck = ""
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if (t[1] == "1" and cou == 1)or(t[1] == "2" and cou == -1):
            frt = t[2] + frt
        else:
            bck = bck + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

s = frt + s + bck
#logging.debug(s)#
if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()  #文字
Q = int(input())  #数字
X = list(input().split() for i in range(Q)) #文字、複数行複数列

#print(X)

for i in range(Q):
    if X[i][0] == "1":
        S = S[::-1]
    else:
        if X[i][1] == "1":
            S = X[i][2] + S
        else:
            S = S + X[i][2]
print(S)

Fixed submission:
s = input()
q = int(input())
cou = 1
frt = ""
bck = ""
for i in range(q):
    t = list(input().split())
    #logging.debug(t)#
    if t[0] == "1":
        cou *= -1
    else:
        if (t[1] == "1" and cou == 1)or(t[1] == "2" and cou == -1):
            frt = t[2] + frt
        else:
            bck = bck + t[2]
#    logging.debug("s {},cou {}".format(s,cou))

s = frt + s + bck
#logging.debug(s)#
if cou == 1:
    print(''.join(s))
else:
    print(''.join(s[::-1]))