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

tmp = ''
rev = False
for _ in range(q):
    query = input().split()

    if query[0] == '1' and not(rev):
        rev = True
    elif query[0] == '1' and rev:
        rev = False

    elif query[0] == '2' and query[1] == '1' and not(rev):
        s = ''.join([query[2], s])

    elif query[0] == '2' and query[1] == '1' and rev:
        s = ''.join([s, query[2]])

    elif query[0] == '2' and query[1] == '2' and not(rev):
        s = ''.join([s, query[2]])

    elif query[0] == '2' and query[1] == '2' and rev:
        s = ''.join([query[2], s])

if rev:
    s = s[::-1]

print(s)


Fixed submission:
s = input()
q = int(input())

sl = ['']*(q*2+2)
sl[q] = s
m = q-1
u = q+1
rev = False
for _ in range(q):
    query = input().split()

    if query[0] == '1' and not(rev):
        rev = True
    elif query[0] == '1' and rev:
        rev = False

    elif query[0] == '2' and query[1] == '1' and not(rev):
        sl[m] = query[2]
        m -= 1

    elif query[0] == '2' and query[1] == '1' and rev:
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and not(rev):
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and rev:
        sl[m] = query[2]
        m -= 1

if rev:
    sl[q] = s[::-1]
    sl.reverse()
    print(''.join(sl))
else:
    print(''.join(sl))

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

rev = False
for _ in range(q):
    query = input().split()

    if query[0] == '1' and not(rev):
        rev = True
    elif query[0] == '1' and rev:
        rev = False

    elif query[0] == '2' and query[1] == '1' and not(rev):
        #s = query[2] + s
        s.insert(0, query[2])
    elif query[0] == '2' and query[1] == '1' and rev:
        #s += query[2]
        s.append(query[2])

    elif query[0] == '2' and query[1] == '2' and not(rev):
        #s += query[2]
        s.append(query[2])
    elif query[0] == '2' and query[1] == '2' and rev:
        #s = query[2]+s
        s.insert(0, query[2])

ans = ''
if rev:
    s.reverse()
    ans = ''.join(s)
else:
    ans = ''.join(s)

print(ans)


Fixed submission:
s = input()
q = int(input())

sl = ['']*(q*2+2)
sl[q] = s
m = q-1
u = q+1
rev = False
for _ in range(q):
    query = input().split()

    if query[0] == '1' and not(rev):
        rev = True
    elif query[0] == '1' and rev:
        rev = False

    elif query[0] == '2' and query[1] == '1' and not(rev):
        sl[m] = query[2]
        m -= 1

    elif query[0] == '2' and query[1] == '1' and rev:
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and not(rev):
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and rev:
        sl[m] = query[2]
        m -= 1

if rev:
    sl[q] = s[::-1]
    sl.reverse()
    print(''.join(sl))
else:
    print(''.join(sl))

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

rev = False
for _ in range(q):
    query = input().split()

    if query[0] == '1' and not(rev):
        rev = True
    elif query[0] == '1' and rev:
        rev = False

    elif query[0] == '2' and query[1] == '1' and not(rev):
        s = query[2] + s
    elif query[0] == '2' and query[1] == '1' and rev:
        s += query[2]

    elif query[0] == '2' and query[1] == '2' and not(rev):
        s += query[2]
    elif query[0] == '2' and query[1] == '2' and rev:
        s = query[2]+s

if rev:
    s=s[::-1]

print(s)


Fixed submission:
s = input()
q = int(input())

sl = ['']*(q*2+2)
sl[q] = s
m = q-1
u = q+1
rev = False
for _ in range(q):
    query = input().split()

    if query[0] == '1' and not(rev):
        rev = True
    elif query[0] == '1' and rev:
        rev = False

    elif query[0] == '2' and query[1] == '1' and not(rev):
        sl[m] = query[2]
        m -= 1

    elif query[0] == '2' and query[1] == '1' and rev:
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and not(rev):
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and rev:
        sl[m] = query[2]
        m -= 1

if rev:
    sl[q] = s[::-1]
    sl.reverse()
    print(''.join(sl))
else:
    print(''.join(sl))

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

for _ in range(q):
    query = input().split()

    if query[0] == '1':
        s = s[::-1]

    elif query[0] == '2' and query[1] == '1':
        s = query[2] + s

    elif query[0] == '2' and query[1] == '2':
        s += query[2]

print(s)


Fixed submission:
s = input()
q = int(input())

sl = ['']*(q*2+2)
sl[q] = s
m = q-1
u = q+1
rev = False
for _ in range(q):
    query = input().split()

    if query[0] == '1' and not(rev):
        rev = True
    elif query[0] == '1' and rev:
        rev = False

    elif query[0] == '2' and query[1] == '1' and not(rev):
        sl[m] = query[2]
        m -= 1

    elif query[0] == '2' and query[1] == '1' and rev:
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and not(rev):
        sl[u] = query[2]
        u += 1

    elif query[0] == '2' and query[1] == '2' and rev:
        sl[m] = query[2]
        m -= 1

if rev:
    sl[q] = s[::-1]
    sl.reverse()
    print(''.join(sl))
else:
    print(''.join(sl))