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

s = input()
d = deque()
num = 0
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            num += 1
        else:
            if num % 2 == 1:
                d.reverse()
            num = 0
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
                
if num% 2 ==1:
    d.reverse()


s = list(d)
s = "".join(s)



print(s)

Fixed submission:
from collections import deque

s = input()
d = deque()
header = 1
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            header *= -1
        else:
            f = int(data[1])
            c = data[2]
            if header == 1:
                if f == 1:
                    d.appendleft(c)
                else:
                    d.append(c)
            else:
                if f == 1:
                    d.append(c)
                else:
                    d.appendleft(c)
                
if header == -1:
    d.reverse()

s = list(d)
s = "".join(s)



print(s)

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

s = input()
d = deque()
num = 0
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            d.reverse()
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)

s = list(d)
s = "".join(s)



print(s)

Fixed submission:
from collections import deque

s = input()
d = deque()
header = 1
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            header *= -1
        else:
            f = int(data[1])
            c = data[2]
            if header == 1:
                if f == 1:
                    d.appendleft(c)
                else:
                    d.append(c)
            else:
                if f == 1:
                    d.append(c)
                else:
                    d.appendleft(c)
                
if header == -1:
    d.reverse()

s = list(d)
s = "".join(s)



print(s)

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

s = input()
d = deque()
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(d) != 1:
                d.reverse()
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
s = list(d)
s = "".join(s)
print(s)

Fixed submission:
from collections import deque

s = input()
d = deque()
header = 1
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            header *= -1
        else:
            f = int(data[1])
            c = data[2]
            if header == 1:
                if f == 1:
                    d.appendleft(c)
                else:
                    d.append(c)
            else:
                if f == 1:
                    d.append(c)
                else:
                    d.appendleft(c)
                
if header == -1:
    d.reverse()

s = list(d)
s = "".join(s)



print(s)

Buggy python submission (verdict: Runtime Error):
from collections import deque

s = input()
d = deque()
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
    data = input().split()
    if len(data) == 1:
      if len(d) != 1:
        tmp1 = d.pop()
        tmp2 = d.popleft()
        d.appendleft(tmp1)
        d.append(tmp2)
      else:
        f = int(data[1])
        c = data[2]
        if f == 1:
          d.appendleft(c)
        else:
          d.append(c)
            
s = list(d)
s = "".join(s)
print(s)

Fixed submission:
from collections import deque

s = input()
d = deque()
header = 1
for i in s:
    d.append(i)
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1 :
            header *= -1
        else:
            f = int(data[1])
            c = data[2]
            if header == 1:
                if f == 1:
                    d.appendleft(c)
                else:
                    d.append(c)
            else:
                if f == 1:
                    d.append(c)
                else:
                    d.appendleft(c)
                
if header == -1:
    d.reverse()

s = list(d)
s = "".join(s)



print(s)