Buggy python submission (verdict: Time Limit Exceeded):
s1 = input()
s2 = s1[::-1]
q = int(input())
x = 0
for i in range(q):
    query = input().split()
    if query[0] == '1':
        x += 1
    else :
        y = x + int(query[1])
        if y % 2 == 0:
            s1 = s1 + query[2]
            s2 = query[2] + s2
        else :
            s1 = query[2] + s1
            s2 = s2 + query[2]
if x % 2 == 0:
    print(s1)
else :
    print(s2)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')

Buggy python submission (verdict: Time Limit Exceeded):
s1 = input()
s2 = s1[::-1]
q = int(input())
x = 0
for i in range(q):
    query = input()
    if query == '1':
        x += 1
    else :
        if (x + int(query[2])) % 2 == 0:
            s1 +=  query[-1]
            s2 = query[-1] + s2
        else :
            s1 = query[-1] + s1
            s2 += query[-1]
if x % 2 == 0:
    print(s1)
else :
    print(s2)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')

Buggy python submission (verdict: Time Limit Exceeded):
s1 = input()
s2 = s1[::-1]
q = int(input())
x = 0
for i in range(q):
    query = input()
    if query == '1':
        x += 1
    else :
        if (x + int(query[2])) % 2 == 0:
            s1 +=  query[-1]
            s2 = query[-1] + s2
        else :
            s1 = query[-1] + s1
            s2 += query[-1]
if x % 2 == 0:
    print(s1)
else :
    print(s2)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
x = 0
for i in range(q):
    query = input()
    if query[0] == '1':
        x += 1
    else :
        if (x + int(query[2])) % 2 == 0:
            s = s + query[-1]
        else :
            s = query[-1] + s
if x % 2 == 0:
    print(s)
else :
    print(s[::-1])

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
x = 0
for i in range(q):
    query = input()
    if query[0] == '1':
        x += 1
    else :
        if (x + int(query[2])) % 2 == 0:
            s = s + query[-1]
        else :
            s = query[-1] + s
if x % 2 == 0:
    print(s)
else :
    print(s[::-1])

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
x = 0
for i in range(q):
    query = input().split()
    if query[0] == '1':
        x += 1
    else :
        y = x + int(query[1])
        if y % 2 == 0:
            s = s + query[2]
        else :
            s = query[2] + s
if x % 2 == 0:
    print(s)
else :
    print(s[::-1])

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())
flag = True
for i in range(q):
    x = input()
    if x == '1':
        flag = not flag
    else :
        if x[2] == '1' and flag :
            s.appendleft(x[4])
        elif x[2] == '2' and not flag :
            s.appendleft(x[4])
        else :
            s.append(x[4])
if flag:
    for i in s :
        print(i, end='')
else :
    for i in range(1, len(s)+1):
        print(s[-i], end='')
print('')