Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    S = readline().decode().strip()
    Q = int(readline())

    cnt = 0

    #空の文字列にqueryで追加する文字を加えていく
    ss = " "
    for _ in range(Q):
        query = list(input().split())
        if query[0] == "1":
            cnt += 1
        else:
            if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
                ss = "".join([query[2],ss])
            else:
                ss = "".join([ss,query[2]])

    #反転回数が奇数の場合、元の文字列とqueryにより作成した文字列を反転
    if cnt%2 == 1:
        S = S[::-1]
        ss = ss[::-1]

    #スペースに元の文字列を追加
    print(ss.replace(" ", S))

if __name__=="__main__":
    main()

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    S = readline().decode().strip()
    Q = int(readline())

    cnt = 0

    #空の文字列にqueryで追加する文字を加えていく
    ss = " "
    for _ in range(Q):
        query = list(input().split())
        if query[0] == "1":
            cnt += 1
        else:
            if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
                ss = "".join([query[2],ss])
            else:
                ss = "".join([ss,query[2]])

    #反転回数が奇数の場合、元の文字列とqueryにより作成した文字列を反転
    if cnt%2 == 1:
        S = S[::-1]
        ss = ss[::-1]

    #スペースに元の文字列を追加
    print(ss.replace(" ", S))

if __name__=="__main__":
    main()

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))

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

    cnt = 0

    #空の文字列にqueryで追加する文字を加えていく
    ss = " "
    for _ in range(Q):
        query = list(input().split())
        if query[0] == "1":
            cnt += 1
        else:
            if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
                ss = "".join([query[2],ss])
            else:
                ss = "".join([ss,query[2]])

    #反転回数が奇数の場合、元の文字列とqueryにより作成した文字列を反転
    if cnt%2 == 1:
        S = S[::-1]
        ss = ss[::-1]

    #スペースに元の文字列を追加
    print(ss.replace(" ", S))

if __name__=="__main__":
    main()

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))

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

cnt = 0

#空の文字列にqueryで追加する文字を加えていく
ss = " "
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        cnt += 1
    else:
        if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
            ss = "".join([query[2],ss])
        else:
            ss = "".join([ss,query[2]])

#反転回数が奇数の場合、元の文字列とqueryにより作成した文字列を反転
if cnt%2 == 1:
    S = S[::-1]
    ss = ss[::-1]

#スペースに元の文字列を追加
print(ss.replace(" ", S))

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))

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

cnt = 0
ss = " "
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        cnt += 1
    else:
        if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
            ss = query[2]+ss
        else:
            ss = ss+query[2]
if cnt%2 == 1:
    S = S[::-1]
    ss = ss[::-1]
print(ss.replace(" ", S))

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))

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

cnt = 0
ss = " "
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        cnt += 1
    else:
        if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
            ss = query[2]+ss
        else:
            ss = ss+query[2]
if cnt%2 == 1:
    S = S[::-1]
    ss = ss[::-1]
print(ss.replace(" ", S))

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))

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

cnt = 0
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        cnt += 1
    else:
        if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
            S = query[2]+S
        else:
            S = S+query[2]
if cnt%2 == 1:
    S = S[::-1]
print(S)

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))

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

cnt = 0
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        cnt += 1
    else:
        if (query[1] == "1" and cnt%2==0) or (query[1] == "2" and cnt%2==1):
            S = query[2]+S
        else:
            S = S+query[2]
if cnt%2 == 1:
    S = S[::-1]
print(S)

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))

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

for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        S = S[::-1]
    else:
        if query[1] == "1":
            S = query[2]+S
        else:
            S = S+query[2]
print(S)

Fixed submission:
s = input()
q = int(input())
list1 = []
list2 = []
flag = 1
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                list1.append(in_line[2])
            else:
                list2.append(in_line[2])
        else:
            if flag == 1:
                list2.append(in_line[2])
            else:
                list1.append(in_line[2])
if flag == 1:
    print("".join(list1[::-1]) + s + "".join(list2))
else:
    print("".join(list2[::-1]) + s[::-1] + "".join(list1))