Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    S_deque = deque(reversed(S_deque))

  else:
    if item[1] == '1':
      S_deque.appendleft(item[2])

    else:
      S_deque.append(item[2])

S = list(S_deque)
print(''.join(S))

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

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

top_flag = 1 # 0なら末尾、1なら最初

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    if top_flag == 0:
      top_flag = 1
    else:
      top_flag = 0

  else:
    in_flag = top_flag + int(item[1])
    if in_flag % 2 == 0:
      S_deque.appendleft(item[2])
    else:
      S_deque.append(item[2])

if top_flag == 0:
  S_deque.reverse()
else:
  pass

print(''.join(S_deque))

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

S_deque = deque(input())
Q = int(input())

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    S_deque = deque(reversed(S_deque))

  else:
    if item[1] == '1':
      S_deque.appendleft(item[2])

    else:
      S_deque.append(item[2])

S = list(S_deque)
print(''.join(S))

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

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

top_flag = 1 # 0なら末尾、1なら最初

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    if top_flag == 0:
      top_flag = 1
    else:
      top_flag = 0

  else:
    in_flag = top_flag + int(item[1])
    if in_flag % 2 == 0:
      S_deque.appendleft(item[2])
    else:
      S_deque.append(item[2])

if top_flag == 0:
  S_deque.reverse()
else:
  pass

print(''.join(S_deque))

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

S_deque = deque(input())
Q = int(input())

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    S_deque.reverse()

  else:
    if item[1] == '1':
      S_deque.appendleft(item[2])

    else:
      S_deque.append(item[2])

S = list(S_deque)
print(''.join(S))

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

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

top_flag = 1 # 0なら末尾、1なら最初

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    if top_flag == 0:
      top_flag = 1
    else:
      top_flag = 0

  else:
    in_flag = top_flag + int(item[1])
    if in_flag % 2 == 0:
      S_deque.appendleft(item[2])
    else:
      S_deque.append(item[2])

if top_flag == 0:
  S_deque.reverse()
else:
  pass

print(''.join(S_deque))

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

S_deque = deque(input())
Q = int(input())

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    S_deque.reverse()

  else:
    if item[1] == '1':
      S_deque.appendleft(item[2])

    else:
      S_deque.append(item[2])

S = list(S_deque)
print(''.join(S))

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

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

top_flag = 1 # 0なら末尾、1なら最初

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    if top_flag == 0:
      top_flag = 1
    else:
      top_flag = 0

  else:
    in_flag = top_flag + int(item[1])
    if in_flag % 2 == 0:
      S_deque.appendleft(item[2])
    else:
      S_deque.append(item[2])

if top_flag == 0:
  S_deque.reverse()
else:
  pass

print(''.join(S_deque))

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

S_deque = deque(input())
Q = int(input())

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    S_deque.reverse()

  else:
    if item[1] == '1':
      S_deque.appendleft(item[2])

    else:
      S_deque.append(item[2])

print(''.join(S_deque))

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

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

top_flag = 1 # 0なら末尾、1なら最初

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    if top_flag == 0:
      top_flag = 1
    else:
      top_flag = 0

  else:
    in_flag = top_flag + int(item[1])
    if in_flag % 2 == 0:
      S_deque.appendleft(item[2])
    else:
      S_deque.append(item[2])

if top_flag == 0:
  S_deque.reverse()
else:
  pass

print(''.join(S_deque))

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

S = list(input())
Q = int(input())

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    S.reverse()

  else:
    if item[1] == '1':
      S_deque = deque(S)
      S_deque.appendleft(item[2])
      S = list(S_deque)

    else:
      S.append(item[2])

print(''.join(S))

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

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

top_flag = 1 # 0なら末尾、1なら最初

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    if top_flag == 0:
      top_flag = 1
    else:
      top_flag = 0

  else:
    in_flag = top_flag + int(item[1])
    if in_flag % 2 == 0:
      S_deque.appendleft(item[2])
    else:
      S_deque.append(item[2])

if top_flag == 0:
  S_deque.reverse()
else:
  pass

print(''.join(S_deque))

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

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    S.reverse()

  else:
    if item[1] == '1':
      S.insert(0, item[2])

    else:
      S.append(item[2])

print(''.join(S))

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

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

top_flag = 1 # 0なら末尾、1なら最初

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    if top_flag == 0:
      top_flag = 1
    else:
      top_flag = 0

  else:
    in_flag = top_flag + int(item[1])
    if in_flag % 2 == 0:
      S_deque.appendleft(item[2])
    else:
      S_deque.append(item[2])

if top_flag == 0:
  S_deque.reverse()
else:
  pass

print(''.join(S_deque))