Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                s = query[i][2] + s
            else:
                s = s + query[i][2]
        else:
            if query[i][1] == '2':
                s = query[i][2] + s
            else:
                s = s + query[i][2]
if rev == 1:
    s = s[::-1]
print(s)

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if int(query[i][1]) == 1:
                s = query[i][2] + s
            else:
                s = s + query[i][2]
        else:
            if int(query[i][1]) == 2:
                s = query[i][2] + s
            else:
                s = s + query[i][2]
if rev == 1:
    s = s[::-1]
print(s)

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if int(query[i][1]) == 1:
                s = query[i][2] + s
            else:
                s = s + query[i][2]
        else:
            if int(query[i][1]) == 2:
                s = query[i][2] + s
            else:
                s = s + query[i][2]
if rev == 1:
    s = s[::-1]
print(s)

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
rev = 0
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if int(query[1]) == 1:
                s = query[2] + s
            else:
                s = s + query[2]
        else:
            if int(query[1]) == 2:
                s = query[2] + s
            else:
                s = s + query[2]
if rev == 1:
    s = s[::-1]
print(s)

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
rev = 0
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if int(query[1]) == 1:
                s = query[2] + s
            else:
                s = s + query[2]
        else:
            if int(query[1]) == 2:
                s = query[2] + s
            else:
                s = s + query[2]
if rev == 1:
    s = s[::-1]
print(s)            

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
rev = 0
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if int(query[1]) == 1:
                s = query[2] + s
            else:
                s = s + query[2]
        else:
            if int(query[1]) == 2:
                s = query[2] + s
            else:
                s = s + query[2]
if rev == 1:
    s = s[::-1]
print(s)            

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
for i in range(q):
    query.append(list(map(str, input().split())))
i = 0
rev = 0
while i < q:
    if len(query[i]) == 1:
        if i < q - 1:
            if len(query[i + 1]) == 1:
                i += 2
                continue
        rev = (rev + 1) % 2
        i += 1
    else:
        if rev == 0:
            if int(query[i][1]) == 1:
                s = query[i][2] + s
                i += 1
            else:
                s = s + query[i][2]
                i += 1
        else:
            if int(query[i][1]) == 2:
                s = query[i][2] + s
                i += 1
            else:
                s = s + query[i][2]
                i += 1
if rev == 1:
    s = s[::-1]
print(s)            

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
for i in range(q):
    query.append(list(map(str, input().split())))
i = 0
while i < q:
    if len(query[i]) == 1:
        if i < q - 1:
            if len(query[i + 1]) == 1:
                i += 2
                continue
        s = s[::-1]
        i += 1
    else:
        if int(query[i][1]) == 1:
            s = query[i][2] + s
            i += 1
        else:
            s = s + query[i][2]
            i += 1
print(s)            

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        s = s[::-1]
    else:
        if int(query[1]) == 1:
            s = query[2] + s
        else:
            s = s + query[2]
print(s)            

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        s = s[::-1]
    else:
        if int(query[1]) == 1:
            s = query[2] + s
        else:
            s = s + query[2]
print(s)            

Fixed submission:
import sys
input = sys.stdin.readline
s = input().rstrip()
q = int(input())
query = []
rev = 0
for i in range(q):
    query.append(list(map(str, input().split())))
sa = []
sb = []
for i in range(q):
    if len(query[i]) == 1:
        rev = (rev + 1) % 2
    else:
        if rev == 0:
            if query[i][1] == '1':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
        else:
            if query[i][1] == '2':
                sa.append(query[i][2])
            else:
                sb.append(query[i][2])
ssa = ''.join(sa)
ssa = ssa[::-1]
ssb = ''.join(sb)
ss = ssa + s + ssb
if rev == 1:
    ss = ss[::-1]
print(ss)