Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)


Fixed submission:
S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)

Buggy python submission (verdict: Time Limit Exceeded):
import math
S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)


Fixed submission:
S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)

Buggy python submission (verdict: Time Limit Exceeded):
import math
S=input()
Q=int(input())
Rev=True
front=""
back=""
for i in range(Q):
    a=input()
    if a=="1":
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == "1":
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)


Fixed submission:
S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)

Buggy python submission (verdict: Time Limit Exceeded):
import math
S=input()
Q=int(input())
Rev=True
front=""
back=""
for i in range(Q):
    a=input()
    if a=="1":
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == "1":
            if Rev:
                front += x
            else:
                back += x
        if c == "2":
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)


Fixed submission:
S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)

Buggy python submission (verdict: Time Limit Exceeded):
import math
S=input()
Q=int(input())
Rev=1
front=""
back=""
for i in range(Q):
    a=input()
    if a=="1":
        Rev=Rev*-1
    else:
        b,c,x=a.split()
        if (c=="1"and Rev==1) or (c=="2" and Rev==-1):
            front+=x
        else:
            back+=x
if Rev==1:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)


Fixed submission:
S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)

Buggy python submission (verdict: Time Limit Exceeded):
import math
S=input()
Q=int(input())
Rev=1
front=""
back=""
for i in range(Q):
    a=input().split()
    if a[0]=="1":
        Rev=Rev*-1
        continue
    if (a[1]=="1"and Rev==1) or (a[1]=="2" and Rev==-1):
        front+=a[2]
    else:
        back+=a[2]
if Rev==1:
    #str(front.reverse().extend(S).extend(back))
    print(front[::-1]+S+back)
    #str(front.reverse()+S+back)
else:
    print(back[::-1]+S[::-1]+front)

Fixed submission:
S=input()
Q=int(input())
Rev=True
front=''
back=''
for i in range(Q):
    a=input()
    if a=='1':
        Rev=not(Rev)
    else:
        b,c,x=a.split()
        if c == '1':
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print(front[::-1] + S + back)
else:
    print(back[::-1]+S[::-1]+front)