Buggy python submission (verdict: Time Limit Exceeded):
import collections

x = collections.deque(input())
n = int(input())

for i in range(n):
    y = input().split()
    if len(y) == 1:
      x.reverse()
    else:
      if int(y[1]) == 2:
          x.append(y[2])
      else:
          x.appendleft(y[2])

print("".join(x))

Fixed submission:
import collections

x = collections.deque(input())
n = int(input())
rev = False

for i in range(n):
    y = input().split()
    if len(y) == 1:
      rev = not rev
    elif rev:
      if int(y[1]) == 2:
          x.appendleft(y[2])
      else:
          x.append(y[2])
    else:
      if int(y[1]) == 2:
          x.append(y[2])
      else:
          x.appendleft(y[2])

if rev:
  x.reverse()

print("".join(x))

Buggy python submission (verdict: Runtime Error):
import collections

x = collections.deque(input())
n = int(input())

for i in range(n):
    y = input()
    if len(y) == 1:
      x.reverse()
    else:
      if int(y[1]) == 2:
          x.append(y[2])
      else:
          x.appendleft(y[2])

print("".join(x))

Fixed submission:
import collections

x = collections.deque(input())
n = int(input())
rev = False

for i in range(n):
    y = input().split()
    if len(y) == 1:
      rev = not rev
    elif rev:
      if int(y[1]) == 2:
          x.appendleft(y[2])
      else:
          x.append(y[2])
    else:
      if int(y[1]) == 2:
          x.append(y[2])
      else:
          x.appendleft(y[2])

if rev:
  x.reverse()

print("".join(x))

Buggy python submission (verdict: Time Limit Exceeded):
import collections

x = collections.deque(input())
n = int(input())
y = 0

for i in range(n):
    a = input()
    if a[0] == "1":
      x.reverse()
    else:
      a, b, c = a.split()
      a = int(a)
      b = int(b)

      if b == 2:
          x.append(c)
      elif b == 1:
          x.appendleft(c)

print("".join(x))

Fixed submission:
import collections

x = collections.deque(input())
n = int(input())
rev = False

for i in range(n):
    y = input().split()
    if len(y) == 1:
      rev = not rev
    elif rev:
      if int(y[1]) == 2:
          x.appendleft(y[2])
      else:
          x.append(y[2])
    else:
      if int(y[1]) == 2:
          x.append(y[2])
      else:
          x.appendleft(y[2])

if rev:
  x.reverse()

print("".join(x))

Buggy python submission (verdict: Time Limit Exceeded):
x = input()
n = int(input())
y = 0

for i in range(n):
    a = input()
    if a[0] == "1":
      x = x[::-1]
    else:
      a, b, c = a.split()
      a = int(a)
      b = int(b)

      if b == 2:
          x = x + c
      elif b == 1:
          x = x[::-1] + c
          x = x[::-1]

print(x)

Fixed submission:
import collections

x = collections.deque(input())
n = int(input())
rev = False

for i in range(n):
    y = input().split()
    if len(y) == 1:
      rev = not rev
    elif rev:
      if int(y[1]) == 2:
          x.appendleft(y[2])
      else:
          x.append(y[2])
    else:
      if int(y[1]) == 2:
          x.append(y[2])
      else:
          x.appendleft(y[2])

if rev:
  x.reverse()

print("".join(x))

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

for i in range(n):
    a = input()
    if a[0] == "2":
      a, b, c = a.split()
      a = int(a)
      b = int(b)

      if b == 1:
          x = x[::-1] + c
          x = x[::-1]
      elif b == 2:
          x = x + c
    else:
        x = x[::-1]

print(x)

Fixed submission:
import collections

x = collections.deque(input())
n = int(input())
rev = False

for i in range(n):
    y = input().split()
    if len(y) == 1:
      rev = not rev
    elif rev:
      if int(y[1]) == 2:
          x.appendleft(y[2])
      else:
          x.append(y[2])
    else:
      if int(y[1]) == 2:
          x.append(y[2])
      else:
          x.appendleft(y[2])

if rev:
  x.reverse()

print("".join(x))