peterverebics/CodeNet_Python_118 huggingface dataset:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
parity = rev % 2
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if (int(qi[2]) + parity) % 2:
            ans.appendleft(qi[4])
        else:
            ans.append(qi[4])


if parity:
    ans.reverse()
for i in ans:
    print(i, end='')
s=input()
n=int(input())
isreverse=False
top=''

for i in range(n):
    ss=input().split()
    if len(ss)==1:
        isreverse=not isreverse
    else:
        if ss[1]=="1":
            if isreverse: s+=ss[2]
            else: top=ss[2]
        else:
            if isreverse: top+=ss[2]
            else: s+=ss[2]
if isreverse:
    s=s[::-1]+top
else:
    s=top[::-1]+s


print(s)
import sys
input = sys.stdin.readline
S = input()[0:1]
Q = int(input())

mode = 1

for i in range(Q):
  TFC = list(map(str, input().split()))
  if "1" in TFC[0]:
    mode *= -1
    continue
  if mode == 1:
    if "1" in TFC[1]:
      S = ''.join([TFC[2],S])
    else:
      S = ''.join([S,TFC[2]])
  else:
    if "1" in TFC[1]:
      S = ''.join([S,TFC[2]])
    else:
      S = ''.join([TFC[2],S])

if mode == 1:
  print(S)
else:
  print(S[::-1])
S = str(input())
Q = int(input())
query=[]
a=""
b=""
# for line in range(Q):
# 	query.append(list(input().split()))
t=True

for i in range(Q):
	q=list(input().split())
	if int(q[0])==1:
		t= not t
	else:
		if int(q[1])==1:
			if t:
				a=q[2]+a
			else:
				b=b+q[2]

		else:
			if t:
				b=b+q[2]
			else:
				a=q[2]+a

if t:
	print(a+S+b)
else:
	print(a[::-1]+S[::-1]+b[::-1])
from collections import deque
S = deque(input().split())
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 0 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
if f % 2 == 0:
  for i in range(len(S)):
    print (S[-i-1], end="")
    print ()
else:
  print (*S, sep="")
S=input()
rev=False
head=""
tail=""
for _ in range(int(input())):
    l = input().split()
    if len(l)==1:
        rev = not rev
    else:
        if rev^(l[1]=="1"):
            tail+=l[2]
        else:
            head+=l[2]
if not rev:
    print("".join(map(str,reversed(head[::-1]+S+tail))))
else:
    print(head[::-1]+S+tail)
S=str(input())
Q=int(input())
for i in range(Q):
    T=str(input().split())
    if T[0]=="1":
        S.reverse()
    elif T[0]=="2":
        if T[1]=="1":
            S=T[2]+S
        elif T[1]=="2":
            S=S+T[2]
print(S)
from collections import deque

s = deque()
s.append(input())
q = int(input())

for i in range(q):
  query = list(map(format, input().split()))
  if int(query[0]) == 1:
    s.reverse()
  else:
    if int(query[1]) == 1:
      s.appendleft(query[2])
    else:
      s.append(query[2])
print(''.join(s))
import sys
input = sys.stdin.readline

s = input()
q = int(input())
par = 0
pre = ""
pos = ""

for i in range(q):
  t = input().split()
  if t[0] == "1":
    par += 1
  elif (par + int(t[1]))%2 == 1:
    pre = t[2] + pre
  else:
    pos = pos + t[2]
    
ans = pre + s + pos

if par%2 == 0:
  print(ans)
else:
  print(ans[::-1])
s = input()
q = int(input())

s = s[::-1]
s = list(s)
for _ in range(q):
    q = input()
    if q[0] == '1':
        s = s[::-1]
    else:
        q = q.split(' ')
        if q[1] == '1':
            s.insert(0,q[-1])
        else:
            s.extend(q[-1])
print(''.join(s))
S = input().split(' ')
Q = int(input())

for _ in range(Q):
    q = input()
    if q == '1':
        S = S[::-1]
    else:
        _, f, c = q.split(' ')
        if f == '1':
            S = [c] + S
        else:
            S = S + [c]

print(''.join(S))
s = input()
q = int(input())
num_1 = 0
tot_1 = 0
for i in range(q):
    l = list(input().split())
    if l[0] == '1':
        num_1 += 1
        tot_1 += 1
    elif l[0] == '2':
        if (num_1 + int(l[1])) % 2 == 0:
            s = s + l[2]
        else:
            s = l[2] + s
        num_1 = 0
if tot_1 % 2 == 1:
    s = s[::-1]
print(s)
#maniawan
import sys
input = sys.stdin.readline

s=input()
q=int(input())

for i in range(q):
    qi=list(input().split())
    if qi[0]=="1":
        s=s[::-1]
    else:
        f,c=qi[1],qi[2]
        if f=="1":
            s=c+s
        else:
            s=s+c
print(s)
s = input()
q = int(input())
flag = False
head = ""
tail = ""
for i in range(q):
    query = input()
    if query[0] == "1":
        flag = not flag
    else:
        [t, f, c] = query.split()
        f = True if f == "1" else False
        if flag == f:
            head += c
        else:
            tail += c
s = head + s + tail
if not flag:
    s = s[::-1]
print(s)
S = input()
Q = int(input())
reverse = 0
left = ""
right = ""
for _ in range(Q):
  q = input().split()
  if q[0]=="1":
    reverse += 1
    left, right = right, left
  if q[0]=="2":
    if q[1]=="1":
      left = q[2]+left
    if q[1]=="2":
      right = right+q[2]
if reverse%2==1:
  left = left[::-1]
  right = right[::-1]
  S = S[::-1]
print(left+S+right)
from collections import deque
d = deque()
S = input()
d.append(S)
s = []
n = int(input())
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
 
for i in range(n):
    if s[i][0] == "1":
        d.reverse()
    else:
        if s[i][1] == "1":
            d.extendleft(s[i][2])
        else:
            d.extend(s[i][2])
 
print("".join(list(d)))
from collections import deque
S = deque()
S.append(input())
N = int(input())
X = []
for i in range(N):
    X.append(input())

for i in range(N):
    if len(X[i]) == 1:
        S.reverse()
    else:
        Y = list(X[i].split())
        if int(Y[1]) == 1:
            S.appendleft(Y[2])
        else:
            S.append(Y[2])

print(''.join(S))
s = str(input())
n = int(input())
num = [str(input()).split() for _ in range(n)]

count=0
ans = [s]
for i in num:
    if int(i[0]) == 1:
        ans=ans[count+1:]+[s]+ans[:count]
        count=len(ans[count:])-1

    else:
        if int(i[1]) == 1:
            count=+1
            ans[0:0]=[i[2]]
        else:
            ans.append(i[2])
print("".join(ans))
s = input()
n = int(input())
tmp  =['',s]
c = 1
for i in range(n):
    t = list(map(str,input().split()))
    if t[0] == '1':
        c+=1
    else:
        C = (c%2==0)
        
        if t[1] == '1':
            C+=1
            C%=2
            tmp[C] = tmp[C] +t[2]
        else:
            tmp[C] = tmp[C] + t[2]
    # print(tmp)
print(tmp[0][::-1]+tmp[1])
S = input()
N = int(input())
Q = []
for _ in range(N):
  Q.append([i for i in input().split()])

from collections import deque
ans = deque([S])

asc = True
for q in Q:
  if q[0] == "2" and ((q[1] == "1" and asc) or (q[1] == "2" and not asc)):
    ans.appendleft(q[2])
  elif q[0] == "2" and ((q[1] == "2" and asc) or (q[1] == "1" and not asc)):
    ans.append(q[2])
  else:
    asc = not asc
if not asc:
  ans.reverse()
print("".join(ans))
from collections import deque
ss=deque()
s=list(input())
l=len(s)
for i in range(l):
    ss.append(s[i])
q=int(input())
info=[]
for i in range(q):
    info.append(list(input().split()))
moji=l
for i in range(q):
    if info[i][0]=="1":
        ss.rotate(moji-1)
    else:
        if info[i][1]=="2":
            ss.append(info[i][2])
        else:
            ss.appendleft(info[i][2])
        moji+=1
    #print(s)
print("".join(ss))
from collections import deque
S=input()
n=int(input())
a=0
for i in range(n):
  q=input()
  if q=="1":
    a+=1
  else:
    p,b,c=q.split()
    if b=="1":
      if a%2==0:
        S=c+S
      else:
        S=S+c
    else:
      if a%2==1:
        S=c+S
      else:
        S=S+c
print(S)
s=input()
q=int(input())
a=[list(map(str,input().split())) for i in range(q)]

ans=[]
ans.append(s)

for i in range(q):
  if len(a[i])==1:
    ans[0],ans[-1]=ans[-1],ans[0]

  else:
    if a[i][1]=='1':
      ans.insert(0,a[i][2])
    else:
      ans.append(a[i][2])

print(''.join(ans))
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
print(Query)
for i in Query:
    if i[0]=="1":
        S = S[::-1]
    else:
        if i[1]=="1":
            S = i[2]+S
        elif i[1]=="2":
            S = S+i[2]
print(S)
#!/usr/bin/env python3
s = input()
Q = int(input())
q = [input().split() for _ in range(Q)]
reverse = 0
start = ""
end = ""
for i in q:
    if i[0] == "1":
        reverse ^= 1
    else:
        if int(i[1]) + reverse >> 0 ^ 0:
            end += i[2]
        else:
            start += i[2]
s = start[::-1] + s + end
print(s[::- 1 + reverse * 2])
s=input()
q=int(input())
ans=s
print(''.join(list(reversed(s))))
for i in range(q):
    a=list(input().split())
    if a[0]=='1':
        ans=''.join(list(reversed(ans)))
    elif a[0]=='2' and a[1]=='1':
        ans=a[2]+ans
    else:
        ans=ans+a[2]

print(ans)
s=input()
q=int(input())
total_t=1
result=[s]
for i in range(q):
  t=input()
  if t=="1":
    total_t=total_t*(-1)
  else:
    f=(t.split())[1]
    c=(t.split())[2]
    if (f=='1' and total_t==1) or (f=='2' and total_t==-1):
      result.insert(0,c)
    else:
      result.append(c)
if total_t==-1:
  result.reverse()
r=''.join(result)
print(r)
from collections import deque
import copy
s = input()
q_ = int(input())
query = [input().split() for _ in range(q_)]
l = deque([s])
flag = 0

for q in query:
    if q[0] == '1':
        flag += 1
    elif q[0] == '2':
        if (int(q[1]) + flag) % 2 == 1:
            l.appendleft(q[2])
        else:
            l.append(q[2])
if flag % 2 == 1:
    l.reverse()
print(''.join(l))
s = input().split()

q=int(input())

for _ in range(q):
    t = input().split()
    if t[0] == '1':
        s.reverse()
    elif t[0] == '2':
        if t[1] == '1':
            s.insert(0, t[2])
        else:
            s.append(t[2])
print(''.join(map(str,s)))
S = str(input())
Q = int(input())
query = [list(map(str,input().split())) for _ in range(Q)]
#print(query)
#
for i in range(Q):
    if query[i][0]=='1':
        S = S[-1]+S[1:-1]+S[0]
    elif query[i][0]=='2':
        if query[i][1]=='1':
            S = query[i][2] + S
        else:
            S = S + query[i][2]
print(S)
s = input()
q = int(input())
swc = 0
top = ""
bot = ""
for i in range(q):
	a = list(map(str, input().split()))
	if a[0] == "1":
		if swc == 0:
			swc = 1
		else:
			swc = 0
	else:
		if swc == 0:
			if a[1] == "1":
				top += a[2]
			else:
				bot += a[2]
		else:
			if a[1] == "1":
				bot += a[2]
			else:
				top += a[2]
if swc == 0:
	top = ''.join(list(reversed(top)))
	print (top + s + bot)
else:
	bot = ''.join(list(reversed(bot)))
	print (bot + s + top)
S = input()
N = int(input())
flg=False
for i in range(N):
	Q = input().split()
	if Q[0] == "1":
		if not flg:
			flg = True
		else:
			Flg = False
	elif Q[0] == "2":
		if Q[1] == "1":
			if not flg:
				S = Q[2]+S
			else:
				S = S+Q[2]
		if Q[1] == "2":
			if flg:
				S = Q[2]+S
			else:
				S = S+Q[2]
if flg:
	S =S[::-1]
print(S)
S = input()

import collections as col
S = col.deque(list(S))

N = int(input())

reversi = 0

for i in range(N):
	L = list(map(str, input().split()))
	if len(L) == 1:
		reversi = reversi^1
	else:
		if reversi == 1:
			if L[1] == 1:
				S.append(L[2])
			else:
				S.appendleft(L[2])
		else:
			if L[1] == 2:
				S.append(L[2])
			else:
				S.appendleft(L[2])

S = list(S)
if reversi == 1:
	print(*S[::-1], sep="")
else:
	print(*S, sep="")
words=[]
words.append(input())
order_amount=int(input())
for i in range(order_amount):
    order=list(input().split())
    if order[0]=='2':
        if order[1]=='1':
            words.insert(0,order[2])
        elif order[1]=='2':
            words.append(order[2])
    else:
        a=words[0]
        words[0]=words[len(words)-1]
        words[len(words)-1]=a
word=''
for i in words:
    word+=i
print(word)
s = input()
q = int(input())
Flag = True
back=''
front=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            front += c
        else:
            back += c

ans = back[::-1] + s + front
print(ans if not Flag else ans[::-1])
s = input()
q = int(input())
appendix = [[], []]
reverse = False
for _ in range(q):
  query = input().split()
  if query[0] == '1':
    reverse ^= True
  else:
    f = bool(int(query[1]) - 1)
    appendix[int(f ^ reverse)].append(query[2])
print(''.join(appendix[int(reverse)][::-1]) + s + ''.join(appendix[int(not reverse)]))
##D
S = str(input())
Q = int(input())
Query = [str(input()) for i in range(Q)]
print(Query)
ans = S
for j in range(len(Query)):
    if Query[j][0] == "1":
        ans = ans[::-1]
    elif Query[j][0] == "2":
        if Query[j][2] == "1":
            ans = str(Query[j][4])+ans
        elif Query[j][2] == "2":
            ans = ans+ str(Query[j][4])
print(ans)
from collections import deque
s = deque(input())
q = int(input())
t = 0
for _ in range(q):
    query = input()
    if query[0] == '1':
        t ^= 1
    else:
        _, f, c = query.split()
        f = int(f)
        if (f - 1) ^ t:
            s.appendleft(c)
        else:
            s.append(c)
ans = ''.join(s)
if t:
    print(ans)
else:
    print(ans[::-1])
S = input()
Q = int(input())
count = 0
lr = ['', '']
for i in range(Q):
    TFC = input()
    if TFC[0] == '1':
        count += 1
    elif TFC[2] == '1':
        lr[count % 2] += TFC[4]
    else:
        lr[(count+1) % 2] += TFC[4]
if count % 2 == 0:
    # print(lr[0][::-1] + S + lr[1])
    print(str(reversed(lr[0])) + S + lr[1])
else:
    print(str(reversed(lr[1])) + str(reversed(S)) + lr[0])
s = [i for i in input()]
n = int(input())
l = [[i for i in input().split()] for _ in range(n)]

front = True

for i in l:
    if i[0] == '1':
        front = not front
    elif i[1] == '1':
        s.append(i[2])
        front = not front
    else:
        s.append(i[2])
            

if front:
    print(*s,sep = '')
else:
    s = s[::-1]
    print(*s,sep = '')
from collections import deque
import sys
input = sys.stdin.readline

s = list(input())
q = int(input())
ans = deque(s)
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        ans.reverse()
    else:
        if arr[1] == '1':
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
print(*ans, sep='')
s = input()
q = int(input())

q_list = []

rev_c = 0
count = 0

for _ in range(q):
  v = input()
  q_list.append(v)
  if v == '1':
    rev_c += 1

for v in q_list:
  if v == '1':
    count += 1
  else:
    num = v[2]
    char = v[4]
    if ((rev_c-count)%2==0 and num=='1') or  ((rev_c-count)%2==1 and num == '2'):
      s = char + s
    else:
      s = s + char
print(s)
if __name__ == '__main__':
    S = list(input())
    Q = int(input())

    for _ in range(Q):
        Query = list(map(str, input().split()))
        if len(Query)==1:
            S[0], S[-1] = S[-1], S[0]
        else:
            if Query[1]=='1':
                S.insert(0, Query[2])
            else:
                S.append(Query[2])
        

    
    ans= ''
    for s in S:
        ans += s
    print(ans)
s = list(input())
q = int(input())
count = 0
for i in range(q):
  l = input().split()
  if l[0] == '1':
    count += 1
  elif l[1] == '1':
    if count % 2 == 0:
      s.insert(0,l[2])
    else:
      s.insert(i+1,l[2])
  else:
    if count % 2 == 0:
      s.insert(i+1,l[2])
    else:
      s.insert(0,l[2])
if count % 2 ==1:
  s = s[::-1]
print(''.join(s))
S=input()
Q=int(input())
lis=[]
for _ in range(Q):
    lis.append(input().split())
ans=S
cnt=0
li=[['2','1',"a"] for i in range(2*100000)]
for i in li:
    if(int(i[0]) == 1):
        cnt= (cnt+1) % 2
    elif((cnt== 0 and i[1]=='1') or (cnt == 1 and i[1]=='2')):
        ans= i[2] + ans
    else:
        ans+=i[2]

print(ans[::-1]) if(cnt % 2 == 1) else print(ans)
s = input()
q = int(input())
ans = 0
 
for i in range(q):
    c = list(map(str, input().split()))
    if c[0] == '1':
        ans +=1
        ans = ans&2
    if c[0] == '2':
        if (int(c[1])+ans)%2== 1 :
          s = c[2] + s
        if (int(c[1])+ans)%2== 0 :
          s = s + c[2]
 
if ans == 1:
  s = s[::-1]
 
print(s)
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+=a[2]
        else:
            back+=a[2]
if Rev==1:
    S=S[::-1]
print(front[::-1]+S+back)
s = input()
q = int(input())
query = [input().split() for _ in range(q)]

ans = s
for i in range(q):
    now = query[i]
    if now == ['1']:
        ans = ans[-1] + ans[1:-1] + ans[0]
    else:
        f = now[1]
        c = now[2]
        if f == '1':
            ans = c + ans
        elif f == '2':
            ans = ans + c

print(ans)
s=input()
n=int(input())
tmp=0
suffix=""
prefix=""
for i in range(n):
	inp=input()
	l=list(inp.split(" "))
	if(len(l)==1):
		tmp+=1
	else:
		ch=l[2]
		op=int(l[1])
		if(tmp%2==1):
			op=3-op
		if(op==1):
			prefix=ch+prefix
		else:
			suffix=suffix+ch
if(tmp%2==1):
	s=s[::-1]
ans=prefix+s+suffix
if(tmp%2==1):
	ans=ans[::-1]
print(ans)
S=list(input())
#print(S)
q=int(input())
x=0
appends=[[] for i in range(2)]
for i in range(q):
    s=list(input().split())
    if int(s[0])==1:
        x+=1
    else:
        appends[(x+int(s[1])+1)%2].append(s[2])
        #print(appends)
S=appends[x%2][::-1]+S+appends[(x+1)%2]
#print(S)
for k in S:
    print(k,end='')
S = input()
Q = int(input())

flag = 1
s1 = ''
s2 = ''

for i in range(Q):
	q = input()
	if len(q) == 1:
		flag = flag * (-1)
	else:
		T,F,C = q.split(' ')
		if flag == 1:
			if int(F) == 1:
				s1 = s1 + C
			else:
				s2 = C + s2
		else:
			if int(F) == 1:
				s2 = C + s2
			else:
				s1 = s1 + C
if flag == 1:
	print(s1 + S + s2)
else:
	print(s2 + S + s1)
s = input()
q = int(input())

ans = [s]
for i in range(q):
    a = input()
    if len(a) == 1:
        ans.reverse()
    else:
        t, p, w = a.split()
        if p == "1":
            ans.insert(0, w)
        else:
            ans.append(w)
print("".join(ans))
S = str(input())
Q = int(input())

topFlg = True

for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        topFlg = not (topFlg)
    else:
        if query[1] == "1":
            S = query[2] + S if topFlg else S + query[2]
        else:
            S = S + query[2] if topFlg else query[2] + S

# if not topFlg:
#     S = S[::-1]

print(S)
ans = [str(input())]
n = int(input())
num = [str(input()).split() for _ in range(n)] 
for i in num:
    if int(i[0]) == 1:
        ans.reverse()
    else:
        if int(i[1]) == 1:
            ans[0:0]=i[2]
        else:
            ans.append(i[2])
print("".join(ans))
from collections import deque
S = deque(list(input()))
Q = int(input())

for _ in range(Q):
    q = list(input().split())
    if q[0] == '1':
        S[0], S[-1] = S[-1], S[0]
    else:
        if q[1] == '1':
            S.appendleft(q[2])
        else:
            S.append(q[2])
print(''.join(S))
from collections import deque

S = input()
Q = int(input())
ans = deque()
ans.append(S)
reverse = False

for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse = not reverse
    else:
        F, C = query[1:]
        if (F == "1" and not reverse) or (F == "2" and reverse):
            ans.appendleft(C)
        else:
            ans.append(C)

if reverse:
    print("".join(reversed(ans)))
else:
    print("".join(ans))
S = input() 
Q = int(input())
for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        pass
    else:
        if lists[1] == "2":
            S = S + lists[2]
        else:
            pass
print(S)
from collections import deque
s = deque(input().rstrip())

nq = int(input().rstrip())
for _ in range(nq):
    query = input().rstrip()
    if query[0] == '1':
        a, b = s.popleft(), s.pop()
        s.appendleft(b)
        s.append(a)
    else:
        _, f, c = query.split()
        if f == '1':
            s.appendleft(c)
        else:
            s.append(c)
print("".join(s))
s = str(input())
q = int(input())

head = ''
back = ''
flg = 1
for _ in range(q):
    i = list(map(str, input().split()))
    if i[0] == '1':
        head, back = back, head
        flg *= -1
    else:
        if i[1] == '1':
            head = i[2] + head
        else:
            back = back + i[2]

if flg == 1:
    print(head[::-1]+s[::-1]+back[::-1])
else:
    print(head + s+ back)
from collections import deque

s = input()
q = int(input())
d = deque()
d.append(s)
for i in range(q):
    query = input().split()
    if query[0] == '1':
        d.reverse()
    elif query[0] == '2':
        if query[1] == '1':
            d.appendleft(query[2])
        elif query[1] == '2':
            d.append(query[2])
ans = ''
l = len(d)
for i in range(l):
    ans += d[i]
print(ans)
moji = input()
n = int(input())
count = 0
count_all = 0
for i in range(n):
  query = input().split()
  if len(query) == 1:
    count += 1
    count_all += 1
  else:
    if (query[1] == "1" and count % 2 == 0) or (query[1] == "2" and count % 2 == 1) :
      moji = query[2] + moji
    else:
      moji = moji + query[2]
    count = 0
if count_all % 2 == 1:
	moji = moji[::-1]
print(moji)
from collections import deque

d = deque()

d.append(input())

q = int(input())

for i in range(q):
    s = input()
    if len(s) == 1:
        t = d.pop()
        h = d.popleft()
        d.append(h)
        d.appendleft(t)
    else:
        l = list(s)
        if l[2] == '1':
            d.appendleft(l[4])
        else:
            d.append(l[4])

for i in range(len(d)):
    print(d[i], end='')

print()
import sys
input = sys.stdin.readline
# print(s)
s = input()
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]

for t in query:
  if t[0] == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      s = c+s
    else:
      s = s+c

print(s[::inv])
import sys
s = sys.stdin.readline().rstrip()
q = int(sys.stdin.readline())
for _ in range(q):
    qi = sys.stdin.readline()         
print(s)
S = list(str(input()))
Q = int(input())

R = 0

for i in range(Q):
    Query = str(input())
    if len(Query) == 1:
        R = (R+1)%2
    else:
        T,F,C = map(str,Query.split())

        if (R + int(F) ) % 2 == 1:
            S.insert(0,C)
        else:
            S.append(C)

for i in range(len(S)):
    print(S[i],end="")
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    if q[0] == '1':
        s_new = s[-1] + s[1:-1] + s[0]
        s = s_new
    else:
        if q[1] == '1':
            s = q[2] + s
        else:
            s += q[2]
print(s)
s=[""]*2
s[1]=input()
q=int(input())
s[0]=""
f=1
for i in range(q):
  a=list(input().split())
  if int(a[0])==1:
    f=(f+1)%2
  else:
    s[(f+int(a[1]))%2]+=a[2]
    
print(s[0][::-1]+s[1])
import sys
input=sys.stdin.readline
s=input().rstrip()
q=int(input())
t=s
cnt=0
for i in range(q):
  qu=list(input().split())
  if qu[0]=='1':
    cnt+=1
  elif qu[0]=='2':
    if (int(qu[1])+cnt)%2==1:
      s=qu[2]+s
      t=t+qu[2]
    else:
      s=s+qu[2]
      t=qu[2]+t
if cnt%2==0:
  print(s)
else:
  print(t)
from collections import deque

S = list(input())
Q = int(input())
d = deque(S)
flag = -1
for _ in range(Q):
    q = list(input().split())
    if q[0] == '1':
        flag *= -1
    else:
        f = int(q[1])
        c = q[2]
        if flag == 1 and f == 1 or flag == -1 and f == 2:
            d.appendleft(c)
        else:
            d.append(c)
d = list(d)
if flag == -1:
    d = d[::-1]

print(''.join(d))
lis = []
s = list(input())
q = int(input())
revcounter = 0
for i in range(1,q+1):
  queue = list(input().split())
  if queue[0] == '1':
    revcounter += 1
  else:
    if queue[1] == '1':
      s.insert(0,queue[2])
    else:
      s.append(queue[2])
if revcounter % 2 == 1:
  s.reverse()
print(''.join(s))
s = input()
q = int(input())

f = ''
b = ''
num = 0
for i in range(q):
    a = input().split()
    if len(a) == 1:
        num ^= 1
        f,b = b,f
    else :
        if a[1] == '1' :
            f = a[2] + f
        elif a[1] == '2' :
            b = b + a[2]

if num:
    print(f[::-1]+s[::-1]+b)
else:
    print(f[::-1]+s+b)