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

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4],0)
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4])
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
S = input().rstrip()
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if len(elem) == 1:
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S = elem[4] + S
    elif s == 2 and flag == 0:
      S += elem[4]
    elif s == 1 and flag == 1:
      S += elem[4]
    else:
      S = elem[4] + S

if flag == 1:
  S = S[::-1]
print(S)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4])
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Que = (input() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if len(elem) == 1:
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S = elem[4] + S
    elif s == 2 and flag == 0:
      S += elem[4]
    elif s == 1 and flag == 1:
      S += elem[4]
    else:
      S = elem[4] + S

if flag == 1:
  S = S[::-1]
print(S)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4])
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input().rstrip()
Q = int(input())

flag = 0 #0:そのまま 1:反転
for _ in range(Q):
  elem = input().rstrip()
  if len(elem) == 1:
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S = elem[4] + S
    elif s == 2 and flag == 0:
      S = S + elem[4]
    elif s == 1 and flag == 1:
      S = S + elem[4]
    else:
      S = elem[4] + S

if flag == 1:
  S = S[::-1]
print(S)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4])
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))