Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
q=int(input())
a=[input()for i in range(q)]
b=0
for i in range(q):
    if a[i]=="1":
        if b==0:
            b=1
        else:
            b=0
    else:
        if b==0:
            if a[i][2]=="1":
                s=a[i][4]+s
            else:
                s=s+a[i][4]
        else:
            if a[i][2]=="1":
                s=s+a[i][4]
            else:
                s=a[i][4]+s
if b==0:
    print(s)
    exit()
s= ''.join(list(reversed(s)))
print(s)


Fixed submission:
s=str(input())
q=int(input())
a=[input()for i in range(q)]
b=0
c=""
d=""
if q<=10**5:
    for i in range(q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    if b==0:
        print(s)
    else:
        s= ''.join(list(reversed(s)))
        print(s)

else:
    for i in range(10**5):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    for i in range(10**5,q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    c=a[i][4]+c
                else:
                    d=d+a[i][4]
            else:
                if a[i][2]=="1":
                    d=d+a[i][4]
                else:
                    c=a[i][4]+c
    if b==0:
        print(c+s+d)
    else:
        c=''.join(list(reversed(c)))
        d=''.join(list(reversed(d)))
        s= ''.join(list(reversed(s)))
        print(d+s+c)

Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
q=int(input())
a=[input()for i in range(q)]

for i in range(q):

    if a[i]=="1":
        s = ''.join(list(reversed(s)))
    
    else:

        if a[i][2]=="1":
            s=a[i][4]+s

        else:
            s=s+a[i][4]


print(s)


Fixed submission:
s=str(input())
q=int(input())
a=[input()for i in range(q)]
b=0
c=""
d=""
if q<=10**5:
    for i in range(q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    if b==0:
        print(s)
    else:
        s= ''.join(list(reversed(s)))
        print(s)

else:
    for i in range(10**5):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    for i in range(10**5,q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    c=a[i][4]+c
                else:
                    d=d+a[i][4]
            else:
                if a[i][2]=="1":
                    d=d+a[i][4]
                else:
                    c=a[i][4]+c
    if b==0:
        print(c+s+d)
    else:
        c=''.join(list(reversed(c)))
        d=''.join(list(reversed(d)))
        s= ''.join(list(reversed(s)))
        print(d+s+c)