Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse = 1
for i in range(Q):
    a = input().split()
    if a[0] == "1":
        reverse *= -1
    elif a[1] == "1":
        if reverse == 1:
            S = a[2] + S
        else:
            S = S + a[2]
    else:
        if reverse == 1:
            S = S + a[2]
        else:
            S = a[2] + S
if reverse == -1:
    S = S[::-1]
print(S)

Fixed submission:
S = input()
Q = int(input())
reverse = 1
head = ""
tail = ""
for i in range(Q):
    a = input().split()
    if a[0] == "1":
        reverse *= -1
    elif a[1] == "1":
        if reverse == 1:
            head += a[2]
        else:
            tail += a[2]
    else:
        if reverse == 1:
            tail += a[2]
        else:
            head += a[2]
# for i in range(Q):
#     a = input().split()
#     if a[0] == "1":
#         reverse *= -1
#     elif a[1] == "1":
#         if reverse == 1:
#             S = a[2] + S
#         else:
#             S = S + a[2]
#     else:
#         if reverse == 1:
#             S = S + a[2]
#         else:
#             S = a[2] + S
S = head[::-1] + S + tail
if reverse == -1:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse = 1
for i in range(Q):
    a = input().split()
    if a[0] == "1":
        reverse *= -1
    elif a[1] == "1":
        if reverse == 1:
            S = a[2] + S
        else:
            S = S + a[2]
    else:
        if reverse == 1:
            S = S + a[2]
        else:
            S = a[2] + S
if reverse == -1:
    S = S[::-1]
print(S)

Fixed submission:
S = input()
Q = int(input())
reverse = 1
head = ""
tail = ""
for i in range(Q):
    a = input().split()
    if a[0] == "1":
        reverse *= -1
    elif a[1] == "1":
        if reverse == 1:
            head += a[2]
        else:
            tail += a[2]
    else:
        if reverse == 1:
            tail += a[2]
        else:
            head += a[2]
# for i in range(Q):
#     a = input().split()
#     if a[0] == "1":
#         reverse *= -1
#     elif a[1] == "1":
#         if reverse == 1:
#             S = a[2] + S
#         else:
#             S = S + a[2]
#     else:
#         if reverse == 1:
#             S = S + a[2]
#         else:
#             S = a[2] + S
S = head[::-1] + S + tail
if reverse == -1:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
# Q_lst = []
# for i in range(Q):
#     Q_lst.append(input().split())
# for i in range(len(Q_lst)):
#     if Q_lst[i] == ["1"]: #T == 1
#         S = S[::-1]
#     elif Q_lst[i][1] == "1":    #T == 2, F == 1
#         S = Q_lst[i][2] + S
#     else:   #F == 2
#         S = S + Q_lst[i][2]
reverse = 1
for i in range(Q):
    a = input().split()
    if a == ["1"]:
        reverse *= -1
    elif a[1] == "1":
        if reverse == 1:
            S = a[2] + S
        else:
            S = S + a[2]
    else:
        if reverse == 1:
            S = S + a[2]
        else:
            S = a[2] + S
if reverse == -1:
    S = S[::-1]
print(S)

Fixed submission:
S = input()
Q = int(input())
reverse = 1
head = ""
tail = ""
for i in range(Q):
    a = input().split()
    if a[0] == "1":
        reverse *= -1
    elif a[1] == "1":
        if reverse == 1:
            head += a[2]
        else:
            tail += a[2]
    else:
        if reverse == 1:
            tail += a[2]
        else:
            head += a[2]
# for i in range(Q):
#     a = input().split()
#     if a[0] == "1":
#         reverse *= -1
#     elif a[1] == "1":
#         if reverse == 1:
#             S = a[2] + S
#         else:
#             S = S + a[2]
#     else:
#         if reverse == 1:
#             S = S + a[2]
#         else:
#             S = a[2] + S
S = head[::-1] + S + tail
if reverse == -1:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Q_lst = []
for i in range(Q):
    Q_lst.append(input().split())
for i in range(len(Q_lst)):
    if Q_lst[i] == ["1"]: #T == 1
        S = S[::-1]
    elif Q_lst[i][1] == "1":    #T == 2, F == 1
        S = Q_lst[i][2] + S
    else:   #F == 2
        S = S + Q_lst[i][2]
print(S)

Fixed submission:
S = input()
Q = int(input())
reverse = 1
head = ""
tail = ""
for i in range(Q):
    a = input().split()
    if a[0] == "1":
        reverse *= -1
    elif a[1] == "1":
        if reverse == 1:
            head += a[2]
        else:
            tail += a[2]
    else:
        if reverse == 1:
            tail += a[2]
        else:
            head += a[2]
# for i in range(Q):
#     a = input().split()
#     if a[0] == "1":
#         reverse *= -1
#     elif a[1] == "1":
#         if reverse == 1:
#             S = a[2] + S
#         else:
#             S = S + a[2]
#     else:
#         if reverse == 1:
#             S = S + a[2]
#         else:
#             S = a[2] + S
S = head[::-1] + S + tail
if reverse == -1:
    S = S[::-1]
print(S)