Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
flag = False
for i in range(Q):
    T = input()
    if T[0]==1:
        flag = not flag
        continue
    if flag:
        S = S[::-1]

    if T[2]=="1":
        S = T[4]+S
        continue
    else:
        S = S+T[4]
        continue
    if i == Q-1 and flag:
        S = S[::-1]
    
print(S)

Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
for _ in range(Q):
    flag = False
    T = input()
  
    if len(T)==1:
        flag = not flag
    else:
      	S = S[::-1]
        if T[2]=="1":
            S = T[4]+S
        else:
              S = S+T[4]
if flag:
    S = S[::-1]
print(S)

Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
flag = False
for _ in range(Q):
    T = input()
  
    if len(T)==1:
        flag = not flag
    else:
      	S = S[::-1]
        if T[2]=="1":
            S = T[4]+S
        else:
              S = S+T[4]
print(S)

Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for _ in range(Q):
    T = input()
  
    if len(T)==1:
        S = S[::-1]
    else:
        if T[2]=="1":
            S = T[4]+S
        else:
              S = S+T[4]
print(S)


Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for _ in range(Q):
    T = input()
  
    if len(T)==1:
        S = S[::-1]
    else:
        if T[2]=="1":
            S = T[4]+S
        else:
              S = S+T[4]
print(S)

Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
for _ in range(Q):
    T = input()
  
    if len(T)==1:
      S = S[::-1]
    else:
	  if T[3]=="1":
          S = T[5]+S
      else:
          S = S+T[5]
print(S)
	
      
    


Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
for _ in range(Q):
  T = input()
  
  if len(T)==1:
    S = S[::-1]
  else:
	if T[3]=="1":
      S = T[5]+S
    else:
      S = S+T[5]
print(S)
	
      
    


Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
S = input()
s_i = 0
Q = int(input())
for _ in range(Q):
  T = input().split()
  if T[0]=="1":
    S = S[::-1]
  else:
	if T[1]=="1":
      S = T[2]+S
    else:
      S = S+T[2]
print(S)
	
      
    


Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
for _ in range(Q):
  T = input()
  
  if len(T)==1:
    S = S[::-1]
  else:
	if T[3]=="1":
      S = T[5]+S
    else:
      S = S+T[5]
print(S)
	
      
    


Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
S = input()
s_i = 0
Q = int(input())
for _ in range(Q):
  T = input().split()
  if T[0]=="1":
    S = S[::-1]
  else:
	if T[1]=="1":
      S = T[2]+S
    else:
      S = S+T[2]
print(S)
	
      
    

Fixed submission:
from collections import deque

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

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)