Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

ans = str(input())
n = int(input())
r = 2

for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            ans = str(x[2]) + ans
        else :
            ans = ans + str(x[2])

if r % 2 == 1 :
    ans = ans[::-1]

print(ans)

Fixed submission:
# coding: utf-8
import sys
from collections import deque
 
ans = str(input())
n = int(input())
r = 2
be=deque()
af=deque()
 
for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            be.appendleft(str(x[2]))
        else :
            af.append(str(x[2]))

ans = ''.join(be) + ans + ''.join(af)
if r % 2 == 1 :
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
sys.setrecursionlimit(4100000)

ans = str(input())
n = int(input())
r = 2

for i in range(n) :
    x = input().split(" ")
    if x[0] == "1" :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            ans = x[2] + ans
        else :
            ans = ans + x[2]

if r % 2 == 1 :
    ans = ans[::-1]

print(ans)

Fixed submission:
# coding: utf-8
import sys
from collections import deque
 
ans = str(input())
n = int(input())
r = 2
be=deque()
af=deque()
 
for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            be.appendleft(str(x[2]))
        else :
            af.append(str(x[2]))

ans = ''.join(be) + ans + ''.join(af)
if r % 2 == 1 :
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

ans = str(input())
n = int(input())
r = 2

for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            ans = str(x[2]) + ans
        else :
            ans = ans + str(x[2])

if r % 2 == 1 :
    ans = ans[::-1]

print(ans)

Fixed submission:
# coding: utf-8
import sys
from collections import deque
 
ans = str(input())
n = int(input())
r = 2
be=deque()
af=deque()
 
for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            be.appendleft(str(x[2]))
        else :
            af.append(str(x[2]))

ans = ''.join(be) + ans + ''.join(af)
if r % 2 == 1 :
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys

ans = str(input())
n = int(input())

for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        ans = ans[::-1]
    else :
        if int(x[1]) == 1 :
            ans = str(x[2]) + ans
        else :
            ans = ans + str(x[2])

print(ans)

Fixed submission:
# coding: utf-8
import sys
from collections import deque
 
ans = str(input())
n = int(input())
r = 2
be=deque()
af=deque()
 
for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            be.appendleft(str(x[2]))
        else :
            af.append(str(x[2]))

ans = ''.join(be) + ans + ''.join(af)
if r % 2 == 1 :
    ans = ans[::-1]

print(ans)