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

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

if rev==-1:
    s = s[::-1]
print("".join(list(s)))

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

if rev==-1:
    s = s[::-1]
print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s = query[i][2]+s
            else:
                s += query[i][2]
        else:
            if query[i][1]=="2":
                s = query[i][2]+s
            else:
                s += query[i][2]

if rev==-1:
    s = s[::-1]
print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q

rev=1

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        rev*=-1
    else:
        r = query[i].split()
        if rev==1:
            if r[1]=="1":
                s = r[2]+s
            else:
                s += r[2]
        else:
            if r[1]=="2":
                s = r[2]+s
            else:
                s += r[2]

if rev==-1:
    s = s[::-1]
print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q

rev=1

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        rev*=-1
    else:
        r = query[i].split()
        if rev==1:
            if r[1]=="1":
                s = r[2]+s
            else:
                s += r[2]
        else:
            if r[1]=="2":
                s = r[2]+s
            else:
                s += r[2]

if rev==-1:
    s = s[::-1]
print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())

query = [""]*q

rev=1

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        rev*=-1
    else:
        r = query[i].split()
        if rev=1:
            if r[1]=="1":
                s = r[2]+s
            else:
                s += r[2]
        else:
            if r[1]=="2":
                s = r[2]+s
            else:
                s += r[2]

if rev=-1:
    s = s[::-1]
print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())

query = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        s = list(reversed(s))
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        else:
            s += r[2]

print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        s = s[::-1]
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        else:
            s += r[2]

print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q
f = [""]*q
c = [""]*q

for i in range(q):
    query[i] = input()

for i in range(q):
    if query[i]=="1":
        s = s[::-1]
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        else:
            s += r[2]

print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q
f = [""]*q
c = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        s = s[::-1]
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        else:
            s += r[2]

print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q
f = [""]*q
c = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        s = s[::-1]
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        elif r[1]=="2":
            s += r[2]

print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q
f = [""]*q
c = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        s = s[::-1]
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        elif r[1]=="2":
            s = s+r[2]

print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())

query = []
t = []
f = []
c = []

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        t.append(1)
    else:
        r = query[i].split()
        t.append(2)
        f.append(int(r[1]))
        c.append(r[2])

for i in range(q):
    if t[i]==1:
        s = s[::-1]
    elif t[i]==2:
        if f[i]==1:
            s = c[i]+s
        elif t[i]==2:
            s = s+c[i]
print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q
t = [0]*q
f = [0]*q
c = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        t[i] = 1
    else:
        r = query[i].split()
        t[i] = 2
        f[i] = int(r[1])
        c[i] = r[2]

for i in range(q):
    if t[i]==1:
        s = s[::-1]
    elif t[i]==2:
        if f[i]==1:
            s = c[i]+s
        elif t[i]==2:
            s = s+c[i]
print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)

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

query = [""]*q
f = [""]*q
c = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        s = s[::-1]
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        elif r[1]=="2":
            s = s+r[2]

print(s)

Fixed submission:
from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)