Buggy python submission (verdict: Runtime Error):
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
if rev == 1:
  S = S[::-1]
print("".join(S))
           
  

Fixed submission:
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
S = "".join(S)
if rev == 1:
  S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S = Q[2] + S
    else:
      S += Q[2]
if rev == 1:
  S = S[::-1]
print(S)
           
  

Fixed submission:
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
S = "".join(S)
if rev == 1:
  S = S[::-1]
print(S)

Buggy python submission (verdict: Runtime Error):
def toku()
  S = input()
  Q = int(input())
  s = [S[0]]
  A = []
  count = 0
  for i in range(Q):
    A += [input().split()]
  for i in range(Q):
    if int(A[i][0]) == 2:
      if count % 2 == 1:
        s = s[::-1]
      count = 0
      if int(A[i][1]) == 1:
        s = [A[i][2]] + s
      else:
        s = s + [A[i][2]]
    else:
      count += 1
      if i == Q-1:
        if count % 2 == 1:
          s = s[::-1]


  result = ''.join(s)
  print(result)


Fixed submission:
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
S = "".join(S)
if rev == 1:
  S = S[::-1]
print(S)

Buggy python submission (verdict: Runtime Error):
def toku()
  S = input()
  Q = int(input())
  s = [S[0]]
  A = []
  count = 0
  for i in range(Q):
    A += [input().split()]
  for i in range(Q):
    if int(A[i][0]) == 2:
      if count % 2 == 1:
        s = s[::-1]
      count = 0
      if int(A[i][1]) == 1:
        s = [A[i][2]] + s
      else:
        s = s + [A[i][2]]
    else:
      count += 1
      if i == Q-1:
        if count % 2 == 1:
          s = s[::-1]


  result = ''.join(s)
  print(result)
toku()


Fixed submission:
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
S = "".join(S)
if rev == 1:
  S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
s = list(S)
for i in range(Q):
  A = input().split()
  if int(A[0]) == 1:
    s = s[::-1]
  else:
    if int(A[1]) == 1:
      s = [A[2]] + s
    else:
      s = s + [A[2]]
result = ''.join(s)
print(result)
  

Fixed submission:
from collections import deque
S = input()
S = deque(S)
N = int(input())

rev = 0

for i in range(N):
  Q = input().split()
  if Q[0] == "1":
    rev += 1
    rev %= 2
  else:
    if (rev + int(Q[1])) % 2 == 1:
      S.appendleft(Q[2])
    else:
      S.append(Q[2])
S = "".join(S)
if rev == 1:
  S = S[::-1]
print(S)