Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
lead = ''
end = ''
inversion_flg = -1

for j in range(q):
    query = input().split()
    if query[0] == "1":
        inversion_flg *= -1
    else:
        if inversion_flg == 1:
            if query[1] == "1":
                query[1] = "2"
            else:
                query[1] = "1"
        if query[1] == "1":
            lead += query[2]
        else:
            end += query[2]

lead = lead[::-1]
s = lead + s + end
if inversion_flg == 1:
    s = s[::-1]
print(s)


Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
 
def func(string, t, f, c):
    if t == "1":
        new_str = ''.join(list(reversed(string)))
        return new_str
    else:
        if f == "1":
            return c + string
        else:
            return string + c
 
for i in range(0,q):
    query.append(input().split())
for i in query:
    if i[0] == "1":
        s = func(s,i[0],'','')
    else:
        s = func(s,i[0],i[1],i[2])
print(s)

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False

for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = 2
            else:
                i[1] = 1
        if int(i[1]) == 1:
            lead+=i[2]
        else:
            end+=i[2]

lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False

for j in range(q):
    i = input().split()
    if int(i[0]) == 1:
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if int(i[1]) == 1:
                i[1] = 2
            else:
                i[1] = 1
        if int(i[1]) == 1:
            lead+=i[2]
        else:
            end+=i[2]

lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False

for j in range(q):
    i = input().split()
    if int(i[0]) == 1:
        inversion_flg = False if inversion_flg else True
    else:
        if inversion_flg:
            i[1] = 2 if int(i[1]) == 1 else 1
        if int(i[1]) == 1:
            lead+=i[2]
        else:
            end+=i[2]

lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False

for i in range(q):
    query.append(input().split())
for i in query:
    if int(i[0]) == 1:
        inversion_flg = False if inversion_flg else True
    else:
        if inversion_flg:
            i[1] = 2 if int(i[1]) == 1 else 1
        if int(i[1]) == 1:
            lead+=i[2]
        else:
            end+=i[2]

lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
 
def func(string, t, f, c):
    if int(t) == 1:
        new_str = ''.join(list(reversed(string)))
        return new_str
    else:
        if int(f) == 1:
            return c + string
        else:
            return string + c
 
for i in range(0,q):
    query.append(input().split())
for i in query:
    if int(i[0]) == 1:
        s = func(s,i[0],'','')
    else:
        s = func(s,i[0],i[1],i[2])
print(s)

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

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

def func(string, t, f, c):
    if int(t) == 1:
        new_str = ''.join(list(reversed(string)))
        return new_str
    else:
        if int(f) == 1:
            return c + string
        else:
            return string + c

for i in range(0,q):
    query.append(input().split())
for i in query:
    if int(i[0]) == 1:
        s = func(s,i[0],'','')
    else:
        s = func(s,i[0],i[1],i[2])
print(s)


Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)