Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
flag = 0
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag%2 == 0:
            if q[1] == "1":
                S = q[2]+S
            else:
                S = S+q[2]
        else:
            if q[1] == "1":
                S = S+q[2]
            else:
                S = q[2]+S
if flag%2 == 0:
    print(S)
else:
    S = S[::-1]
    print(S)

Fixed submission:
S = input()
Q = int(input())
flag = 0
H = ""
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag%2 == 0:
            if q[1] == "1":
                H = H+q[2]
            else:
                S = S+q[2]
        else:
            if q[1] == "1":
                S = S+q[2]
            else:
                H = H+q[2]
H = H[::-1]
H = H+S
if flag%2 == 0:
    print(H)
else:
    H = H[::-1]
    print(H)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
S = []
A = []
B = []
for i in range(len(s)):
  S.append(s[i])
Q = int(input())
flag = 0
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag % 2 == 0:         
            if q[1] == "1":
                A.insert(0,q[2])
            else:
                B.append(q[2])
        else:
            if q[1] == "1":
                B.append(q[2])
            else:
                A.insert(0,q[2])
if flag%2 == 0:
    A = "".join(A)
    B = "".join(B)
    S = "".join(S)
    print(A+S+B)
else:
    S = S[::-1]
    S = "".join(S)
    A = A[::-1]
    A = "".join(A)
    B = B[::-1]
    B = "".join(B)
    print(B+S+A)

Fixed submission:
S = input()
Q = int(input())
flag = 0
H = ""
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag%2 == 0:
            if q[1] == "1":
                H = H+q[2]
            else:
                S = S+q[2]
        else:
            if q[1] == "1":
                S = S+q[2]
            else:
                H = H+q[2]
H = H[::-1]
H = H+S
if flag%2 == 0:
    print(H)
else:
    H = H[::-1]
    print(H)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
S = []
for i in range(len(s)):
  S.append(s[i])
Q = int(input())
flag = 0
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag % 2 == 0:         
            if q[1] == "1":
                S.insert(0,q[2])
            else:
                S.append(q[2])
        else:
            if q[1] == "1":
                S.append(q[2])
            else:
                S.insert(0,q[2])
if flag%2 == 0:
    S = "".join(S)
    print(S)
else:
    S = S[::-1]
    S = "".join(S)
    print(S)

Fixed submission:
S = input()
Q = int(input())
flag = 0
H = ""
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag%2 == 0:
            if q[1] == "1":
                H = H+q[2]
            else:
                S = S+q[2]
        else:
            if q[1] == "1":
                S = S+q[2]
            else:
                H = H+q[2]
H = H[::-1]
H = H+S
if flag%2 == 0:
    print(H)
else:
    H = H[::-1]
    print(H)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
flag = 0
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag % 2 == 0:         
            if q[1] == "1":
                S = q[2]+S
            else:
                S = S + q[2]
        else:
            if q[1] == "1":
                S = S + q[2]
            else:
                S = q[2]+S
if flag%2 == 0:
    print(S)
else:
    S = S[::-1]
    print(S)

Fixed submission:
S = input()
Q = int(input())
flag = 0
H = ""
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag%2 == 0:
            if q[1] == "1":
                H = H+q[2]
            else:
                S = S+q[2]
        else:
            if q[1] == "1":
                S = S+q[2]
            else:
                H = H+q[2]
H = H[::-1]
H = H+S
if flag%2 == 0:
    print(H)
else:
    H = H[::-1]
    print(H)