Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
T = [input() for i in range(Q)]

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        S = "".join([t[4], S])
      else:
        S = "".join([S, t[4]])
    else:
      if(count):
        S = "".join([S, t[4]])
      else:
        S = "".join([t[4], S])

if(count):
  print(S)
else:
  print(S[::-1])


Fixed submission:
from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
T = [input() for i in range(Q)]

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        list = [t[4], S]
        S = "".join(list)
      else:
        list = [S, t[4]]
        S = "".join(list)
    else:
      if(count):
        list = [S, t[4]]
        S = "".join(list)
      else:
        list = [t[4], S]
        S = "".join(list)

if(count):
  print(S)
else:
  print(S[::-1])


Fixed submission:
from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
T = [input() for i in range(Q)]

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        S = f"{t[4]}{S}"
      else:
        S = f"{S}{t[4]}"
    else:
      if(count):
        S = f"{S}{t[4]}"
      else:
        S = f"{t[4]}{S}"

if(count):
  print(S)
else:
  print(S[::-1])


Fixed submission:
from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
T = [input() for i in range(Q)]

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        S = t[4] + S
      else:
        S = S + t[4]
    else:
      if(count):
        S = S + t[4]
      else:
        S = t[4] + S

if(count):
  print(S)
else:
  print(S[::-1])


Fixed submission:
from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
T = [input() for i in range(Q)]

left = ""
right = ""

for i in range(Q):
  s = T[i]
  if(int(s[0]) == 2):
    if(int(s[2]) == 1):
      left = s[4] + left
    else:
      right = right + s[4]
  else:
    S = left + S + right
    S = S[::-1]
    left = ""
    right = ""
S = left + S + right

print(S)

Fixed submission:
from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
T = [input() for i in range(Q)]

count = True

for i in range(Q):
  if(int(T[i][0]) == 1):
    count = not count
  else:
    if(int(T[i][2]) == 1):
      S = T[i][4] + S if count else S + T[i][4]
    else:
      S = S + T[i][4] if count else T[i][4] + S

if(count):
  print(S)
else:
  print(S[::-1])


Fixed submission:
from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
T = [input() for i in range(Q)]

count = 0

for i in range(Q):
  if(int(T[i][0]) == 1):
    count += 1
  else:
    if(int(T[i][2]) == 1):
      if(count % 2 == 0):
        S = T[i][4] + S
      else:
        S = S + T[i][4]
    else:
      if(count % 2 == 0):
        S = S + T[i][4]
      else:
        S = T[i][4] + S

if(count % 2 == 0):
  print(S)
else:
  print(S[::-1])


Fixed submission:
from collections import deque
S = input()
Q = int(input())
T = [input() for i in range(Q)]

d =deque(S)

count = True

for i in range(Q):
  t = T[i]
  if(int(t[0]) == 1):
    count = not count
  else:
    if(int(t[2]) == 1):
      if(count):
        d.appendleft(t[4])
      else:
        d.append(t[4])
    else:
      if(count):
        d.append(t[4])
      else:
        d.appendleft(t[4])

ans = list(d)

if(count):
  print("".join(ans))
else:
  print("".join(ans[::-1]))