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


Fixed submission:
from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):

s=input()
q=int(input())
n=0
for i in range(q):
    l=input().split()
    if l[0]=='1':
        n+=1
    else:
        if (l[1]=='1' and n%2==0) or (l[1]=='2' and n%2==1):
            s=l[2]+s
        else:
            s=s+l[2]
if n%2==0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):

s=input()
q=int(input())
n=0
for i in range(q):
    l=input().split()
    if l[0]=='1':
        n+=1
    else:
        if (l[1]=='1' and n%2==0) or (l[1]=='2' and n%2==1):
            s=l[2]+s
        else:
            s=s+l[2]
if n%2==0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):

s=input()
q=int(input())
for i in range(q):
    l=input().split()
    if l[0]=='1':
        s=s[::-1]
    else:
        if l[1]=='1':
            s=l[2]+s
        else:
            s=s+l[2]

print(s)


Fixed submission:
from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])

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


Fixed submission:
from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
n=0
for i in range(q):
    li=input().split()
    if int(li[0])==1:
        n+=1
    elif int(li[0])==2:
        if (n%2==0 and int(li[1])==1) or (n%2==1 and int(li[1])==2):
            s=li[2]+s
        else:
            s=s+li[2]
if n%2==0:
    print(s)
else:
    st=list(s)
    st.reverse()
    print(''.join(st))


Fixed submission:
from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())
n=0
for i in range(q):
    li=input().split()
    if int(li[0])==1:
        n+=1
    elif int(li[0])==2:
        if (n%2==0 and int(li[1])==1) or (n%2==1 and int(li[1])==2):
            s.insert(0,li[2])
        else:
            s.append(li[2])
if n%2==0:
    print(''.join(s))
else:
    s.reverse()
    print(''.join(s))


Fixed submission:
from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())
n=0
for i in range(q):
    li=input().split()
    if int(li[0])==1:
        s.reverse()
    elif int(li[0])==2:
        if (n%2==0 and int(li[1])==1) or (n%2==1 and int(li[1])==2):
            s.insert(0,li[2])
        else:
            s.append(li[2])
if n%2==0:
    print(''.join(s))
else:
    s.reverse()
    print(''.join(s))


Fixed submission:
from collections import deque
s=input()
q=int(input())
n=0
que=deque(s)
for i in range(q):
    l=input()
    if l[0]=='1':
        n+=1
    else:
        if (l[2]=='1' and n%2==0) or (l[2]=='2' and n%2==1):
            que.appendleft(l[4])
        else:
            que.append(l[4])

ans=''.join(que)
if n%2==0:
    print(ans)
else:
    print(ans[::-1])