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

qs = list()
for i in range(Q):
    qs.append(input().split())

ns = s
cnt_r = 0
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                ns = ns + c
            else:
                ns = c + ns
        else:
            if cnt_r % 2 == 1:
                ns = c + ns
            else:
                ns = ns + c

if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)


Fixed submission:
s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

# ns = s
cnt_r = 0
bs, es = '', ''
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                es += c
                # ns = ns + c
            else:
                bs = c + bs
                # ns = c + ns
        else:
            if cnt_r % 2 == 1:
                bs = c + bs
                # ns = c + ns
            else:
                es += c
                # ns = ns + c

ns = bs + s + es
if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)

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

# qs = list()
# for i in range(Q):
#     qs.append(input().split())

ns = s
cnt_r = 0
for i in range(Q):
    q = input().split()
# for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                ns = ns + c
            else:
                ns = c + ns
        else:
            if cnt_r % 2 == 1:
                ns = c + ns
            else:
                ns = ns + c

if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)

Fixed submission:
s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

# ns = s
cnt_r = 0
bs, es = '', ''
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                es += c
                # ns = ns + c
            else:
                bs = c + bs
                # ns = c + ns
        else:
            if cnt_r % 2 == 1:
                bs = c + bs
                # ns = c + ns
            else:
                es += c
                # ns = ns + c

ns = bs + s + es
if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)

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

qs = list()
for i in range(Q):
    qs.append(input().split())

ns = s
# for i in range(Q):
    # q = input().split()
for q in qs:
    if len(q) == 1:
        ns = ns[::-1]
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            ns = c + ns
        else:
            ns = ns + c

print(ns)


Fixed submission:
s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

# ns = s
cnt_r = 0
bs, es = '', ''
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                es += c
                # ns = ns + c
            else:
                bs = c + bs
                # ns = c + ns
        else:
            if cnt_r % 2 == 1:
                bs = c + bs
                # ns = c + ns
            else:
                es += c
                # ns = ns + c

ns = bs + s + es
if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)

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

# qs = list()
# for i in range(q):
#     qs.append(input().split())

ns = s
for i in range(q):
    query = input().split()
    if len(query) == 1:
        ns = ns[::-1]
    else:
        f, c = int(query[1]), query[2]
        if f == 1:
            ns = c + ns
        else:
            ns = ns + c

print(ns)


Fixed submission:
s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

# ns = s
cnt_r = 0
bs, es = '', ''
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                es += c
                # ns = ns + c
            else:
                bs = c + bs
                # ns = c + ns
        else:
            if cnt_r % 2 == 1:
                bs = c + bs
                # ns = c + ns
            else:
                es += c
                # ns = ns + c

ns = bs + s + es
if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)