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

flag = 0
cnt = 0
n = int(input())

for i in range(n):
    que = input()
    if(len(que) == 1):
        cnt += 1
    else:
        que = que.split()
        if(que[1]=="1" and cnt%2 == 0):
            s = que[2] + s
        if(que[1]=="1" and cnt%2 == 1):
            s = s + que[2]
        if(que[1]=="2" and cnt%2 == 0):
            s = s +que[2] 
        if(que[1]=="2" and cnt%2 == 1):
            s = que[2] + s

if(cnt%2 == 0):
    print(s)
else:
    print(s[::-1])

Fixed submission:
s = input()

flag = 0
cnt = 0
n = int(input())

que_ar = [input() for _ in range(n)]

f_x = ["" for _ in range(n)]
b_x = ["" for _ in range(n)]


f = n-1
b = 0

for i in range(n):
    que = que_ar[i]
    if(len(que) == 1):
        cnt += 1
    else:
        que = que.split()
        if(cnt%2 == 0):
            if(que[1]=="1"):
                f_x[f] = que[2]
                f -= 1
            else:
                b_x[b] = que[2]
                b += 1
        else:
            if(que[1]=="1"):
                b_x[b] = que[2]
                b += 1
            else:
                f_x[f] = que[2]
                f -= 1

s = "".join(f_x)+s+"".join(b_x)             
                
if(cnt%2 == 0):
    print(s)
else:
    print(s[::-1])

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

flag = 0
cnt = 0
n = int(input())

for i in range(n):
    que = input()
    if(len(que) == 1):
        cnt += 1
    else:
        que = que.split()
        if(que[1]=="1" and cnt%2 == 0):
            s = que[2] + s
        if(que[1]=="1" and cnt%2 == 1):
            s = s + que[2]
        if(que[1]=="2" and cnt%2 == 0):
            s = s +que[2] 
        if(que[1]=="2" and cnt%2 == 1):
            s = que[2] + s

if(cnt%2 == 0):
    print(s)
else:
    print(s[::-1])



Fixed submission:
s = input()

flag = 0
cnt = 0
n = int(input())

que_ar = [input() for _ in range(n)]

f_x = ["" for _ in range(n)]
b_x = ["" for _ in range(n)]


f = n-1
b = 0

for i in range(n):
    que = que_ar[i]
    if(len(que) == 1):
        cnt += 1
    else:
        que = que.split()
        if(cnt%2 == 0):
            if(que[1]=="1"):
                f_x[f] = que[2]
                f -= 1
            else:
                b_x[b] = que[2]
                b += 1
        else:
            if(que[1]=="1"):
                b_x[b] = que[2]
                b += 1
            else:
                f_x[f] = que[2]
                f -= 1

s = "".join(f_x)+s+"".join(b_x)             
                
if(cnt%2 == 0):
    print(s)
else:
    print(s[::-1])

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

flag = 0
#print(len(s))
if(len(s) > 1):
    flag = 1
    s_save = s[1:-1]
    s = s[0]+"123"+s[-1]
 
n = int(input())

for i in range(n):
    que = input()
    if(len(que) == 1):
        s = s[::-1]
    else:
        que = que.split()
        if(que[1]=="1"):
            s = que[2] + s
        else:
            s = s + que[2]


if(flag == 0):
    print(s)
else:
    if("123" in s):
        print(s.replace("123",s_save))
    else:
        print(s.replace("321",s_save[::-1]))



Fixed submission:
s = input()

flag = 0
cnt = 0
n = int(input())

que_ar = [input() for _ in range(n)]

f_x = ["" for _ in range(n)]
b_x = ["" for _ in range(n)]


f = n-1
b = 0

for i in range(n):
    que = que_ar[i]
    if(len(que) == 1):
        cnt += 1
    else:
        que = que.split()
        if(cnt%2 == 0):
            if(que[1]=="1"):
                f_x[f] = que[2]
                f -= 1
            else:
                b_x[b] = que[2]
                b += 1
        else:
            if(que[1]=="1"):
                b_x[b] = que[2]
                b += 1
            else:
                f_x[f] = que[2]
                f -= 1

s = "".join(f_x)+s+"".join(b_x)             
                
if(cnt%2 == 0):
    print(s)
else:
    print(s[::-1])

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

for i in range(n):
    que = input()
    if(len(que) == 1):
        s = s[::-1]
    else:
        que = que.split()
        if(que[1]=="1"):
            s = que[2] + s
        else:
            s = s + que[2]

print(s)

Fixed submission:
s = input()

flag = 0
cnt = 0
n = int(input())

que_ar = [input() for _ in range(n)]

f_x = ["" for _ in range(n)]
b_x = ["" for _ in range(n)]


f = n-1
b = 0

for i in range(n):
    que = que_ar[i]
    if(len(que) == 1):
        cnt += 1
    else:
        que = que.split()
        if(cnt%2 == 0):
            if(que[1]=="1"):
                f_x[f] = que[2]
                f -= 1
            else:
                b_x[b] = que[2]
                b += 1
        else:
            if(que[1]=="1"):
                b_x[b] = que[2]
                b += 1
            else:
                f_x[f] = que[2]
                f -= 1

s = "".join(f_x)+s+"".join(b_x)             
                
if(cnt%2 == 0):
    print(s)
else:
    print(s[::-1])

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

for i in range(n):
    que = input()
    if(len(que) == 1):
        s = s[::-1]
    else:
        que = que.split()
        if(que[1]=="1"):
            s = que[2] + s
        else:
            s = s + que[2]

print(s)

Fixed submission:
s = input()

flag = 0
cnt = 0
n = int(input())

que_ar = [input() for _ in range(n)]

f_x = ["" for _ in range(n)]
b_x = ["" for _ in range(n)]


f = n-1
b = 0

for i in range(n):
    que = que_ar[i]
    if(len(que) == 1):
        cnt += 1
    else:
        que = que.split()
        if(cnt%2 == 0):
            if(que[1]=="1"):
                f_x[f] = que[2]
                f -= 1
            else:
                b_x[b] = que[2]
                b += 1
        else:
            if(que[1]=="1"):
                b_x[b] = que[2]
                b += 1
            else:
                f_x[f] = que[2]
                f -= 1

s = "".join(f_x)+s+"".join(b_x)             
                
if(cnt%2 == 0):
    print(s)
else:
    print(s[::-1])