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

s = list(input())
s.pop(-1)
q = int(input())

r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
    #s.reverse()
    #s = s[::-1]
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
      if r % 2 == 1:
        s.insert(0, tfc[2])
      else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')



Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
 
r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.appendleft(tfc[2])
        #s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
     if r % 2 == 1:
        s.appendleft(tfc[2])
     else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
      if r % 2 == 1:
        s.insert(0, tfc[2])
      else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
 
r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.appendleft(tfc[2])
        #s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
     if r % 2 == 1:
        s.appendleft(tfc[2])
     else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    s.reverse()
  else:
    if tfc[1] == '1':
      s.insert(0, tfc[2])
    else:
      s.append(tfc[2])
for i in s:
  print(i, end='')

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
 
r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.appendleft(tfc[2])
        #s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
     if r % 2 == 1:
        s.appendleft(tfc[2])
     else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')

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

s = input()
q = int(input())

for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    s.reverse()
    #s = s[::-1]
  else:
    if tfc[1] == '1':
      s = tfc[2] + s
    else:
      s = s + tfc[2]
print(s)

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
 
r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.appendleft(tfc[2])
        #s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
     if r % 2 == 1:
        s.appendleft(tfc[2])
     else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    s = s[::-1]
  else:
    if tfc[1] == '1':
      s = tfc[2] + s
    else:
      s = s + tfc[2]
print(s)


Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
 
r = 0
for i in range(q):
  tfc = input().split()
  if tfc[0] == '1':
    r += 1
  else:
    if tfc[1] == '1':
      if r % 2 == 0:
        s.appendleft(tfc[2])
        #s.insert(0, tfc[2])
      else:
        s.append(tfc[2])
    if tfc[1] == '2':
     if r % 2 == 1:
        s.appendleft(tfc[2])
     else:
        s.append(tfc[2])          
if r % 2 == 0:
  for i in s:
      print(i, end='')
else:
  for i in (reversed(s)):
    print(i, end='')