Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s = l[i][2] + s
        sc += l[i][2]
    else:
        s += l[i][2]
        sc = l[i][2] + sc

print(s)

Fixed submission:
import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))

Buggy python submission (verdict: Runtime Error):
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

#last = 1

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    
if last > 0:
    print(s)
else:
    print(sc)

Fixed submission:
import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

#last = 1

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s = l[i][2] + s
        sc += l[i][2]
    else:
        s += l[i][2]
        sc = l[i][2] + sc

print(s)

Fixed submission:
import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

last = 1

for i in range(n):
    if l[i][0] == '1':
        last = last * -1
    elif l[i][1] == '1' and last > 0:
            s = l[i][2] + s
            sc += l[i][2]
    elif l[i][1] == '2' and last > 0:
            s += l[i][2]
            sc = l[i][2] + sc
    elif l[i][1] == '1' and last < 0:
            s += l[i][2]
            sc = l[i][2] + sc
    else:
            s = l[i][2] + s
            sc += l[i][2]

if last > 0:
    print(s)
else:
    print(sc)

Fixed submission:
import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

last = 1

for i in range(n):
    if l[i][0] == '1':
        last = last * -1
    else:
        if l[i][1] == '1' and last > 0:
            s = l[i][2] + s
            sc += l[i][2]
        elif l[i][1] == '2' and last > 0:
            s += l[i][2]
            sc = l[i][2] + sc
        elif l[i][1] == '1' and last < 0:
            s += l[i][2]
            sc = l[i][2] + sc
        else:
            s = l[i][2] + s
            sc += l[i][2]

if last > 0:
    print(s)
else:
    print(sc)

Fixed submission:
import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

last = 1

for i in range(n):
    if l[i][0] == '1':
        last = last * -1
    else:
        if l[i][1] == '1' and last > 0:
            s = l[i][2] + s
            sc += l[i][2]
        elif l[i][1] == '2' and last > 0:
            s += l[i][2]
            sc = l[i][2] + sc
        elif l[i][1] == '1' and last < 0:
            s += l[i][2]
            sc = l[i][2] + sc
        else:
            s = l[i][2] + s
            sc += l[i][2]

if last > 0:
    print(s)
else:
    print(sc)

Fixed submission:
import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        s = s[::-1]
    else:
        if l[i][1] == '1':
            s = l[i][2] + s
        else:
            s += l[i][2]
print(s)

Fixed submission:
import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))