Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

T = 0
F = 2
C = 4

s = input()
q = int(input())

# query = [input().split() for l in range(q)]





# print(s,q,query)

cnt = 0

for i in range(q):
    query = input()

    # print(query[i])
    if query[T] == "1":
        cnt += 1
        continue

    # print(s)
    if cnt % 2 == 0:
        # print(query[i])
        if query[F] == "1":
            s = query[C] + s
            # print(s)
        else:
            s = s + query[C]

    else:
        # print(query[i])
        if query[F] == "1":
            # print(s)
            s = s + query[C]
        else:
            s = query[C] + s

if cnt % 2 == 0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
# -*- coding: utf-8 -*-

T = 0
F = 2
C = 4

s = input()
q = int(input())

cnt = 0

front = ""
back = ""

for i in range(q):
    query = input()

    if query[T] == "1":
        cnt += 1
        continue

    # モード通常
    if cnt % 2 == 0:
        if query[F] == "1":
            front +=  query[C]
        else:
            back += query[C]

    # モード反転
    else:
        if query[F] == "1":
            back += query[C]
        else:
            front +=  query[C]


# print(cnt)
# print(front)
# print(s)
# print(back)

# moji = front+s+back

if cnt % 2 == 0:
    print(front[::-1]+s+back)
    pass
else:
    print(back[::-1]+s[::-1]+front)
    # print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

T = 0
F = 1
C = 2

s = input()
q = int(input())

query = [input().split() for l in range(q)]

# print(s,q,query)

cnt = 0

for i in range(q):
    # print(query[i])
    if query[i][T] == "1":
        cnt += 1
        continue

    # print(s)
    if cnt % 2 == 0:
        # print(query[i])
        if query[i][F] == "1":
            s = query[i][C] + s
            # print(s)
        else:
            s = s + query[i][C]

    else:
        # print(query[i])
        if query[i][F] == "1":
            # print(s)
            s = s + query[i][C]
        else:
            s = query[i][C] + s

if cnt % 2 == 0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
# -*- coding: utf-8 -*-

T = 0
F = 2
C = 4

s = input()
q = int(input())

cnt = 0

front = ""
back = ""

for i in range(q):
    query = input()

    if query[T] == "1":
        cnt += 1
        continue

    # モード通常
    if cnt % 2 == 0:
        if query[F] == "1":
            front +=  query[C]
        else:
            back += query[C]

    # モード反転
    else:
        if query[F] == "1":
            back += query[C]
        else:
            front +=  query[C]


# print(cnt)
# print(front)
# print(s)
# print(back)

# moji = front+s+back

if cnt % 2 == 0:
    print(front[::-1]+s+back)
    pass
else:
    print(back[::-1]+s[::-1]+front)
    # print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

T = 0
F = 1
C = 2


s = input()
q = int(input())

query = [input().split() for l in range(q)]

# print(s,q,query)


for i in range(q):
    if query[i][T] == "2":
        # print(query[i])
        if query[i][F] == "1":
            s = query[i][C]+s
            # print(s)
        else :
            s = s+query[i][C]
    else:
        s = s[::-1]


print(s)




Fixed submission:
# -*- coding: utf-8 -*-

T = 0
F = 2
C = 4

s = input()
q = int(input())

cnt = 0

front = ""
back = ""

for i in range(q):
    query = input()

    if query[T] == "1":
        cnt += 1
        continue

    # モード通常
    if cnt % 2 == 0:
        if query[F] == "1":
            front +=  query[C]
        else:
            back += query[C]

    # モード反転
    else:
        if query[F] == "1":
            back += query[C]
        else:
            front +=  query[C]


# print(cnt)
# print(front)
# print(s)
# print(back)

# moji = front+s+back

if cnt % 2 == 0:
    print(front[::-1]+s+back)
    pass
else:
    print(back[::-1]+s[::-1]+front)
    # print(s[::-1])