Buggy python submission (verdict: Time Limit Exceeded):
*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.insert(0, c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.insert(0, c)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))


Fixed submission:
*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.append(c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.append(c)

*l, = reversed(l)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
_q = int(input())
rev = 0
l, r = "", ""
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l = c+l
        else:
            r += c
    else:
        if f == "1":
            r += c
        else:
            l = c+l

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))


Fixed submission:
*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.append(c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.append(c)

*l, = reversed(l)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
_q = int(input())
rev = 0
l, r = "", ""
for _ in range(_q):
    *q, = map(str, input().split())
    q.extend([" ", " "])
    t = q[0]
    f = q[1]
    c = q[2]

    if t == "1":
        rev += 1
    else:
        if rev%2 == 0:
            if f == "1":
#                s.insert(0, c)
                l = c+l
            else:
#                s.append(c)
                r += c
        else:
            if f == "1":
#                s.append(c)
                r += c
            else:
#                s.insert(0, c)
                l = c+l

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))


Fixed submission:
*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.append(c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.append(c)

*l, = reversed(l)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
*s, = input()
_q = int(input())
r = 0
for _ in range(_q):
    *q, = map(str, input().split())
    q.extend([" ", " "])
    t = q[0]
    f = q[1]
    c = q[2]

    if t == "1":
        r += 1
    else:
        if r%2 == 0:
            if f == "1":
                s.insert(0, c)
            else:
                s.append(c)
        else:
            if f == "1":
                s.append(c)
            else:
                s.insert(0, c)

if r%2 == 1:
    *s, = reversed(s)

print("".join(s))


Fixed submission:
*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.append(c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.append(c)

*l, = reversed(l)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
*s, = input()
_q = int(input())
for _ in range(_q):
    *q, = map(str, input().split())
    q.extend([" ", " "])
    t = q[0]
    f = q[1]
    c = q[2]

    if t == "1":
        *s, = reversed(s)
    else:
        if f == "1":
            s.insert(0, c)
        else:
            s.append(c)

print("".join(s))


Fixed submission:
*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.append(c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.append(c)

*l, = reversed(l)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))