Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

s = input().strip('\n')
q = int(input().strip('\n'))

j = ''.join
turn = 0
for _ in range(q):
    query = input().strip('\n')
    if len(query) == 1:
        turn += 1
    else:
        two, f, c = query.split()
        if f == '1':
            if turn % 2 == 0:
                s = j([c, s])
            else:
                s = j([s, c])
        else:
            if turn % 2 == 0:
                s = j([s, c])
            else:
                s = j([c, s])

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

Fixed submission:
import sys
input = sys.stdin.readline

s = input().strip()
q = int(input())
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print(right[::-1] + s[::-1] + left)
else:
    print(left[::-1] + s + right)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

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

j = ''.join
turn = 0
for _ in range(q):
    query = input()
    if len(query) == 1:
        turn += 1
    else:
        two, f, c = query.split()
        if f == '1':
            if turn % 2 == 0:
                s = j([c, s])
            else:
                s = j([s, c])
        else:
            if turn % 2 == 0:
                s = j([s, c])
            else:
                s = j([c, s])

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

Fixed submission:
import sys
input = sys.stdin.readline

s = input().strip()
q = int(input())
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print(right[::-1] + s[::-1] + left)
else:
    print(left[::-1] + s + right)

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

j = ''.join
turn = 0
for _ in range(q):
    query = input()
    if len(query) == 1:
        turn += 1
    else:
        two, f, c = query.split()
        if f == '1':
            if turn % 2 == 0:
                s = j([c, s])
            else:
                s = j([s, c])
        else:
            if turn % 2 == 0:
                s = j([s, c])
            else:
                s = j([c, s])

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

Fixed submission:
import sys
input = sys.stdin.readline

s = input().strip()
q = int(input())
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print(right[::-1] + s[::-1] + left)
else:
    print(left[::-1] + s + right)

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

turn = 0
for _ in range(q):
    query = input()
    if len(query) == 1:
        turn += 1
    else:
        two, f, c = query.split()
        if f == '1':
            if turn % 2 == 0:
                s = ''.join([c, s])
            else:
                s = ''.join([s, c])
        else:
            if turn % 2 == 0:
                s = ''.join([s, c])
            else:
                s = ''.join([c, s])

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

Fixed submission:
import sys
input = sys.stdin.readline

s = input().strip()
q = int(input())
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print(right[::-1] + s[::-1] + left)
else:
    print(left[::-1] + s + right)

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
exchange = 0

for _ in range(q):
  query = input()
  if query == '1':
    excnange += 1
  else:
    t, f, c = query.split()
    if f == '1':
      s = c + s
    else:
      s = s + c
      
if exchange % 2 == 0:
  print(s)
else:
  print(s[::-1])


Fixed submission:
import sys
input = sys.stdin.readline

s = input().strip()
q = int(input())
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print(right[::-1] + s[::-1] + left)
else:
    print(left[::-1] + s + right)

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

for _ in range(q):
  query = input()
  if query == '1':
    s = s[::-1]
  else:
    t, f, c = query.split()
    if f == '1':
      s = c + s
    else:
      s = s + c
      
print(s)


Fixed submission:
import sys
input = sys.stdin.readline

s = input().strip()
q = int(input())
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print(right[::-1] + s[::-1] + left)
else:
    print(left[::-1] + s + right)