Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
    s = "".join([c,s])
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()

Fixed submission:
from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()

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

now_reverse = False
l = [s]
tmp = ''



for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    s = "".join([s,c])
  elif f == '1' and not now_reverse:
    s = "".join([c,s])
  elif f == '2' and now_reverse:
    s = "".join([c,s])
  else:
    s = "".join([s,c])
  
if now_reverse:
  s = reversed(s)

for c in s:
  print(c,end='')
print()

Fixed submission:
from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()

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

now_reverse = False
l = [s]
tmp = ''

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    l.append(-1)
    tmp = 0
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    s = "{}{}".format(s,c)
  elif f == '1' and not now_reverse:
    s = "{}{}".format(c,s)
  elif f == '2' and now_reverse:
    s = "{}{}".format(c,s)
  else:
    s = "{}{}".format(s,c)
  
if now_reverse:
  s = reversed(s)

for c in s:
  print(c,end='')
print()

Fixed submission:
from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()

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

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    s = s + c
  elif f == '1' and not now_reverse:
    s = c + s
  elif f == '2' and now_reverse:
    s = c + s
  else:
    s = s + c
  
if now_reverse:
  s = reversed(s)

for c in s:
  print(c,end='')
print()

Fixed submission:
from collections import deque
s = input()
n = int(input())
d = deque(s)

now_reverse = False

for _ in range(n):
  query = input()

  if query == '1':
    now_reverse = not now_reverse
    continue

  
  _,f,c = query.split()
  if f == '1' and now_reverse:
    d.append(c)
  elif f == '1' and not now_reverse:
    d.appendleft(c)
  elif f == '2' and now_reverse:
    d.appendleft(c)
  else:
    d.append(c)
  
if now_reverse:
  d = reversed(list(d))
else:
  d =list(d)

for c in d:
  print(c,end='')
print()