Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
num = 0
ans = "0"

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans = query[2] + ans
      else:
        ans = ans + query[2]
    else:
      if num%2 == 0:
        # 後方
        ans = ans + query[2]
      else:
        ans = query[2] + ans
        
mes = ans.replace("0", s)
if num%2 == 0:
  print(mes)
else:
  mes = ''.join(list(reversed(mes)))
  print(mes)

Fixed submission:
from collections import deque
s = input()
q = int(input())
num = 0
ans = deque(s)

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:
      if num%2 == 0:
        # 後方
        ans.append(query[2])
      else:
        ans.appendleft(query[2])     

if num%2 == 0:
  print(''.join(ans))
else:
  ans.reverse()
  print(''.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
num = 0
ans = "0"

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans = query[2] + ans
      else:
        ans = ans + query[2]
    else:
      if num%2 == 0:
        # 後方
        ans = ans + query[2]
      else:
        ans = query[2] + ans
        
mes = ans.replace("0", s)
if num%2 == 0:
  print(mes)
else:
  print(mes[::-1])

Fixed submission:
from collections import deque
s = input()
q = int(input())
num = 0
ans = deque(s)

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:
      if num%2 == 0:
        # 後方
        ans.append(query[2])
      else:
        ans.appendleft(query[2])     

if num%2 == 0:
  print(''.join(ans))
else:
  ans.reverse()
  print(''.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
ans = input()
q = int(input())
num = 0

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans = query[2] + ans
      else:
        ans = ans + query[2]
    else:
      if num%2 == 0:
        # 後方
        ans = ans + query[2]
      else:
        ans = query[2] + ans

if num%2 == 0:
  print(ans)
else:
  print(ans[::-1])

Fixed submission:
from collections import deque
s = input()
q = int(input())
num = 0
ans = deque(s)

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:
      if num%2 == 0:
        # 後方
        ans.append(query[2])
      else:
        ans.appendleft(query[2])     

if num%2 == 0:
  print(''.join(ans))
else:
  ans.reverse()
  print(''.join(ans))

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

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    #反転
    ans = ans[::-1]
  else:
    if int(query[1]) == 1:
      # 先頭
      ans = query[2] + ans
    else:
      # 後方
      ans = ans + query[2]

print(ans)

Fixed submission:
from collections import deque
s = input()
q = int(input())
num = 0
ans = deque(s)

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:
      if num%2 == 0:
        # 後方
        ans.append(query[2])
      else:
        ans.appendleft(query[2])     

if num%2 == 0:
  print(''.join(ans))
else:
  ans.reverse()
  print(''.join(ans))

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

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    #反転
    ans = ''.join(list(reversed(ans)))
  else:
    if int(query[1]) == 1:
      # 先頭
      ans = query[2] + ans
    else:
      # 後方
      ans = ans + query[2]

print(ans)

Fixed submission:
from collections import deque
s = input()
q = int(input())
num = 0
ans = deque(s)

for _ in range(q):
  query = list(input().split())
  if len(query) == 1:
    num += 1
  else:
    if int(query[1]) == 1:
      if num%2 == 0:        
        # 先頭
        ans.appendleft(query[2])
      else:
        ans.append(query[2])
    else:
      if num%2 == 0:
        # 後方
        ans.append(query[2])
      else:
        ans.appendleft(query[2])     

if num%2 == 0:
  print(''.join(ans))
else:
  ans.reverse()
  print(''.join(ans))