Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    left_ = left
    if rev == 1:
        if f == '1':
            left_ = left[::-1]
            left_.append(c)
            left_ = left_[::-1]
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left_ = left[::-1]
            left_.append(c)
            left_ = left_[::-1]
    return left_, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left+S+right)[::rev])

Fixed submission:
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left[::-1]+S+right)[::rev])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    left_ = left
    if rev == 1:
        if f == '1':
            left_ = [c] + left
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left_ = [c] + left
    return left_, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left+S+right)[::rev])

Fixed submission:
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left[::-1]+S+right)[::rev])

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left_ = [c] + left
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left_ = [c] + left
    return left_, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left+S+right)[::rev])

Fixed submission:
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left[::-1]+S+right)[::rev])

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left_ = [c] + left
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left_ = [c] + left
    return left_, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left+S+right)[::rev])

Fixed submission:
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left[::-1]+S+right)[::rev])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
S = input().split()
Q = int(input())

def pop(s, rev, f, c):
    ret = s
    if rev == 1:
        if f == '1':
            ret = [c] + s
        else:
            ret = s + [c]
    else:
        if f == '1':
            ret = s + [c]
        else:
            ret = [c] + s
    return ret


left, right = '', ''
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        S = pop(S, rev, *que[1:])
print(''.join(S)[::rev])

Fixed submission:
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left[::-1]+S+right)[::rev])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
S = input()
Q = int(input())

def pop(s, rev, f, c):
    ret = s
    if rev == 1:
        if f == '1':
            ret = c + s
        else:
            ret = s + c
    else:
        if f == '1':
            ret = s + c
        else:
            ret = c + s
    return ret


rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        S = pop(S, rev, *que[1:])
print(S[::rev])

Fixed submission:
# coding: utf-8
S = input().split()
Q = int(input())

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print(''.join(left[::-1]+S+right)[::rev])