peterverebics/CodeNet_Python_118 huggingface dataset:
def main():
  s = [input()]
  n = int(input()) 
  str_list = [list(input().split()) for _ in range(n)]

  for item in str_list:
    if int(item[0]) == 1:
      s.reverse()
    elif int(item[0]) == 2:
      if int(item[1]) == 1:
        s.insert(0, item[2])
      elif int(item[1]) == 2:
        s.append(item[2])
  print(''.join(s))

if __name__ == '__main__':
    main()
from collections import deque

s=input()
n=int(input())
q=deque()
q.append(s)
for i in range(n):
    t=list(input().split())
    if t[0]=='1':
        l=reversed(list(q))
        q=deque(l)
    else:
        if t[1]=='1':
            q.appendleft(t[2])
        else:
            q.append(t[2])

print(''.join(q))
def main():
    S=[input()]
    for i in range(int(input())):
        T = input()
        if T == '1':
            S = S[::-1]
        else:
            ta = T.split()
            F = int(ta[1])
            C = ta[2]
            if F == 1:
                S.insert(0, C)
            else:
                S.append(C)

    print(''.join(S))

main()
S = [input()]
Q = int(input())

for i in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        S = S[::-1]
    else:
        F = int(q[1])
        C = q[2]
        if F == 1:
            S.insert(0, C)
        else:
            S.append(C)

print("".join(S))
S = input()
Q = int(input())

cur = 1
res = [S]
for _ in range(Q):
    xs = input().split()

    if len(xs) == 1:
        cur = 2 if cur == 1 else 1
    else:
        _, f, c = xs
        if f == cur == 1 or f == cur == 2:
            res = res + [c]
        else:
            res = [c] + res

if cur == 1:
    ans = "".join(res)
else:
    ans = "".join(res[::-1])

print(ans)
from collections import deque
S = input()
que = deque()
que.append(S)
Q = int(input())
Front_flag = 1

for i in range(Q):
    Query = tuple(input().split())
    if len(Query) == 1:
        Front_flag = 1 - Front_flag
    else:
        a, b, c = Query
        if (Front_flag + int(b)) % 2 == 1:
            que.append(c)
        else:
            que.appendleft(c)
if not Front_flag:
    que.reverse()

ans = ''.join(que)
print(ans)
S = input()
Q = int(input())
#query = [input().split() for _ in range(Q)]
rev = False
forw = ""
back = ""
for i in range(Q):
  query = input().split()
  if query[0] == "1":
    rev = not rev
  else:
    if (not rev and query[1] == "1") or (rev and query[1] == "2"):
      forw = query[2] + forw
    else:
      back += query[2]
S = forw + S + back
#print(S)
if rev:
  #print(S[::-1])
  for i in range(0,len(S), -1) :
    print(S[i], end="")
  #S = back[::-1] + S[::-1] + forw[::-1]
else:
  #S = forw + S + back
  print(S)
S = input()
Q = int(input())
P = []
for n in range(Q):
    P.append(input().split())
ans = [S]
for i in P:
    if len(i) == 1:
        ans.reverse()
    else:
        if i[1] == "1":
            ans = [i[2]] + ans
        else:
            ans = ans + [i[2]]
print("".join(ans))
s = input()

q = int(input())
r = 0
b = ""
c = ""
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        r += 1
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] != '1' and r % 2 != 0):
            b = A[2] + b
        else:
            c = c + A[2]
s = b+s+c
if r % 2 == 0:
    print(s)
else:
    s = reversed(s)
    print(s)
s = str(input())
Q = int(input())
S = {}

c = 0
x = [c]
S[c] = s
ss = ''

for i in range(Q):
    c+=1
    q = input()
    if q == '1':
        x[0], x[-1] = x[-1], x[0]
    else:
        _, fi, ci = q.split()
        S[c] = ci
        if fi == '1':
            x.insert(0, c)
        if fi == '2':
            x.append(c)

for i in x:
    ss += S[i]
print(ss)
S = input()
Q = int(input())
fg = False
que2 = []
que2.append(S)

for _ in range(Q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        que2.reverse()
    elif que[0] == "2" and que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.append(que[2])
        
ans = "".join(que2)
print(ans)
s=input()
n=int(input())
front=""
end=""
reverse=False

for i in range(n):
  t=input().split()
  if t==["1"]:
    reverse=not reverse
  else:
    if (t[1]=="1")^reverse:
      front=front+t[2]
    else:
      end=end+t[2]
if reverse:
  print(end[::-1]+s+front)
else:
  print(front[::-1]+s+end)
from collections import deque

s = str(input())
Q = int(input())
x = deque()
x.append(s)
for i in range(Q):
	qu = input()
	if qu == '1':
		x.reverse()
	else:
		q, fi, ci = qu.split()
		if q == '2':
			if fi == '1':
				x.appendleft(ci)
			if fi == '2':
				x.append(ci)
print(''.join(x))
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']:
        if len(ans) != 1:
            ans = ans[-1] + ans[1:-1] + ans[0]
        else:
            continue
    else:
        f = now[1]
        c = now[2]
        if f == '1':
            ans = c + ans
        elif f == '2':
            ans = ans + c

print(ans)
s = [input()]
q = int(input())
for i in range(q):
    inp = input().split()
    if len(inp) == 1:
        s = s[::-1]
    else:       
        if int(inp[1])==1:
            s.append(inp[2])
        else:
            s.insert(0,inp[2])
print(''.join(s))
s = [input()]
n = int(input())

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        s.insert(0, q[2])
    else:
        s.append(q[2])


if div:
    print(''.join(s))
else:
    s.reverse()
    print(''.join(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][0],S])
    else:
      S = ''.join([S,TFC[2][0]])
  else:
    if "1" in TFC[1]:
      S = ''.join([S,TFC[2][0]])
    else:
      S = ''.join([TFC[2][0],S])

if mode == 1:
  print(S)
else:
  print(S[::-1])
#s
s=input()
#q
q=int(input())

l_empty = []

for i in range(q):
    l_empty = []
    #t
    t=input().split()
    if t[0] == "1":
        s = s[::-1]
    elif t[1] == "1":
        l_empty.append(s)
        l_empty.append(t[2])
        s = "".join(l_empty)
    else:
        l_empty.append(t[2])
        l_empty.append(s)
        s = "".join(l_empty)
print(s)
s = input()
try:
    while True:
        query = input()
        if len(query) == 1:
            s = s[::-1]
            continue

        s = query[-1] + s if query[2] == "1" else s + query[-1]
except:
    pass
print(s)
s=input()
q=int(input())
t=[input() for i in range(q)]

l=[s]
for i in range(q):
  if int(t[i][0])==1:
    l.reverse()
  else:
    if int(t[i][2])==1:
      l.insert(0,t[i][4]) 
    else:
      l.extend(t[i][4])
print(''.join(l))
s = input()
q = int(input())

head = []
tail = []
flip = 0

for i in range(q):
	query = input().split()
	if query[0] == '1':
		flip ^= 1
	else:
		f = query[1]
		c = query[2]
		# if (f ^ flip) == 0:
		if f == '1' or flip == 1:
			head.append(c)
		else:
			tail.append(c)

if flip:
	head, tail = tail, head
	s = s[::-1]

head = ''.join(head)
tail = ''.join(tail)

print(head[::-1] + s + tail)
S = input()
Q = int(input())

for i in range(1,Q+1):
    T = input()
    if len(T) == 1:
        L = ''
        for j in range(len(S)):
            L += S[-j-1]
    else:
        if T[2] == '1':
            S = T[4] + S
        elif T[2] == '2':
            S = S + T[4]
print(S)
S = str(input())
Q = int(input())
ans = S
mode = 1
for _ in range(Q):
  q_in = str(input())
  if q_in == '1':
    mode *= -1
    continue
  else:
    t, f_in, c = map(str, q_in.split())
    f = int(f_in)
    if mode == -1:
      if f_in == 1:
        f = 2
      else:
        f = 1
    if f == 1:
      ans = c + ans
    else:
      ans = ans + c

if mode == -1:
  ans = ans[::-1]

print(ans)
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '1':
        key = -key
    
    else:
        S = S + i[4]

        if i[2] == '1':
            key = -key

print(S[::key])
def main():
    s = input().split()
    q = int(input())
    query = []
    for i in range(q):
        query.append(input().split(" "))
    for i in range(q):
        if query[i][0] == '1':
            s.reverse()
        else:
            if query[i][1] == '1':
                s.insert(0, query[i][2])
            else:
                s.append(query[i][2])
    print("".join(s))

if __name__ == "__main__":
    main()
S = input()
Q = int(input())
R = 1
Top = []
Bottom = []
for _ in range(Q):
  inp = input()
  if inp[0]=='1':
    R *= -1
  else:
    o, f, c = inp.split()
    if f=='1' and R==-1 or f=='2' and R==1:
      Bottom.append(c)
    else:
      Top.insert(0, c)
S = Top + [S] + Bottom
S = S if R==1 else reversed(S)
S = ''.join(S)
print(S)
S = list(input())
Q = int(input())
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:
            S.insert(0, c)
        else:
            S.append(c)

if flag == -1:
    S = S[::-1]

print(''.join(S))
s = list(input())
q = int(input())


for i in range(q):
    buf = input().split()
    if len(buf) == 1:
        s_first = s[0]
        s_last = s[-1]
        s[0] = s_last
        s[-1] = s_first

    if len(buf) == 3:
        if buf[1] == '1':
            s.insert(0, buf[2])
        if buf[1] == '2':
            s.append(buf[2])

for i in range(len(s)):
    print(s[i], end="")
import numpy as np
S=str(input())
Q=int(input())
A=np.array([])
m=0
T=""
for j in range(Q):
  L=list(map(str,input().split()))
  if L[0]=="1":
    A=np.array(A*(-1))
  else:
    S=S+L[2]
    if L[1]==1:
      A=np.append(A,-1)
    else:
      A=np.append(A,1)
for i in range(len(T)):
  if A[i]==-1:
    S=T[i]+S
  else:
    S=S+T[i]
print(S)
S = input()
N = int(input())
for i in range(N):
  X = input().split()
  NS = S
  if len(X) == 1 and len(S) != 1:
    NS = S[-1] + S[1:-1] + S[0]
  else:
    if X[1] == "1":
      NS = X[2] + S
    else:
      NS = S + X[2]
  S = NS
print(S)
from collections import deque
S=deque([input()])
q=int(input())
rev=False
for i in range(q):
   s=input()
   if s=="1":
      rev= not rev
   else:
      t,f,c=s.split()
      if (rev and f=="1") or (not rev and f=="2"):
         S.append(c)
      else:
         S.appendleft(c)
if not rev:
   print("".join(S))
else:
   print("".join(reversed(S)))
s=input()
q=int(input())

rev=1

sf=s
sb=""

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])
import sys

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

re=False
for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==True:
            s=[q_i[2]]+s
        elif q_i[1]=="2" and re==False:
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

if re==True:
    s=s[::-1]

s="".join(s)
print(s)
s = input()
n = int(input())

ct = 0

for i in range(n):
    p = input().split()

    if p[0] == '1':
        ct += 1
    else:
        if p[1] == "2":
            ct += 1
        
        if ct % 2 :
            s = s + p[2]
        else:
            s = p[2] + s
        ct = 0

if ct % 2 :
    s = s[::-1]
    
print(s)
from collections import deque
S=input()
N=int(input())
Q=[input() for i in range(N)]
T=deque(S)
for i in range(N):
    if Q[i][0]=="2":
        if Q[i][2]=="1":
            T.appendleft(Q[i][4])
            S=list(T)
        if Q[i][2]=="2":
            T.append(Q[i][4])
            S=list(T)
    if Q[i][0]=="1":
        S=list(T)
        S=S[::-1]
        T=deque(S)
print(str(S))
s = str(input())
Q = int(input())
S = {}

c = 0
x = [c]
S[c] = s

for i in range(Q):
    c+=1
    q = input()
    if q == '1':
        x[0], x[-1] = x[-1], x[0]
    else:
        _, fi, ci = q.split()
        S[c] = ci
        if fi == '1':
            x.insert(0, c)
        if fi == '2':
            x.append(c)

si = [S[i] for i in x]
print(''.join(si))
from collections import deque
d = deque()
s = input()
d.append(s)


Q = int(input())

for q in range(Q):
    ls = input().split()
    #print (ls)
    if ls[0] == '1':
        d.reverse()
    else:
        if (ls[1]== '1'):
            d.appendleft(ls[2])
        else:
            d.append(ls[2])

ans = ''.join(list(d))

print (ans)
import sys
input = sys.stdin.readline

s = input().split()[0]
q = int(input())

left, right = [], []
state = 1
for _ in range(q):
    q_i = input().split()
    if len(q_i) == 1:
        state = 2
    else:
        _, f, c = q_i
        f = int(f)
        if (f+state)%2 == 0:
            left += [c]
        else:
            right += [c]
if state == 1:
    print(''.join(left[::-1]) + s + ''.join(right))
else:
    print(''.join(right[::-1]) + s + ''.join(left))
S = input()
Q = int(input())
top = ''
end = ''
reverse_flag = 1
for _ in range(Q):
    query = input()
    if len(query) == 1:
        reverse_flag *= -1
    else:
        _, F, C = query.split()
        if (int(F)-1.5) * reverse_flag == 1:
            end += C
        else:
            top += C

if reverse_flag == 1:
    ans = (top[::-1] + S + end)
    print(ans)
else:
    ans = (end[::-1] + S[::-1] + top)
    print(ans)
s = list(input())
q = int(input())
for i in range(q):
  l = list(map(str, input().split()))
  if l[0] == '1':
    s = s[::-1]
  elif l[1] == '1':
    s.insert(0,l[2])
  else:
    s.insert(i+1,l[2])
print(''.join(s))
import sys
input = sys.stdin.readline
s = input()

n = int(input())

#y = []
#for i in range(n):
#    x = input()
#    y.append(x)
#
#print(y)
#print(y[0].split())
for i in range(n):
    x = input()
    if int(x[0]) == 1:
        s = s[::-1]
    else:
        x = x.split()
        if int(x[1]) == 1:
            s = x[2] + s

        else:
            s = s + x[2]


print(s)
from collections import deque

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

cnt=0

for i in range(q):
  x=input()
  if x=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      Q.appendleft(x[4])
      
    else:
      Q.append(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))
s = input()
q = int(input())
rev = False
for i in range(q):
  inp = input()
  if int(inp[0]) == 1:
    rev = not rev
  else:
    t, f, c = inp.split()
    if (int(f) == 1 and rev) or (int(f) == 2 and not rev):
      s += c
    else:
      s = c + s
print(reversed(s) if rev else s)
from collections import deque
s = list(input())
queue = deque(s)

q = int(input())
for i in range(q):
    query = list(input().split(" "))
    if len(query) == 1:
        l = queue.popleft()
        r = queue.pop()
        queue.append(l)
        queue.appendleft(r)
    else:
        if query[1] == "1":
            queue.appendleft(query[2])
        else:
            queue.append(query[2])

print("".join(list(queue)))
s=input()
Q=int(input())
hanten = 0
mae = []
ushiro = []
for i in range(Q):
	q=input()
	if q=="1":
		hanten ^= 1
	else:
		if q[2] == "1":
			if hanten == 0:
				mae.append(q[4])
			else:
				ushiro.append(q[4])
		else:
			if hanten == 0:
				ushiro.append(q[4])
			else:
				mae.append(q[4])
if hanten == 0:
	print("".join(mae)[::-1] + s + "".join(ushiro))
else:
	print("".join(ushiro)[::-1] + s +"".join(mae))
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]
  Q = int(input())

  q = deque([S])
  reverse = False
  for i in range(Q):
    line = input().split()
    if line[0] == '1':
      reverse = not(reverse)
    else:
      if reverse ^ (int(line[1])-1):
        # S = S + line[2]
        q.append(line[2])
      else:
        # S = line[2] + S
        q.appendleft(line[2])

  print(''.join(reversed(q)) if reverse else ''.join(q))


if(__name__ == '__main__'):
  main()
s = str(input())
n = int(input())

stat = 0
front = ""
back = ""

for _ in range(n):
    q = input()

    # 反転の場合
    if q[0] == "1":
        stat = (stat + 1) % 2
        continue

    # q = q.split()

    judge = int(q[2])
    if stat == 1:
        if judge == 1:
            judge = 2
        elif judge == 2:
            judge = 1

    if judge == 1:
        front = q[4] + front 

    if judge == 2:
        back = back + q[4]

s = front + s + back

print(s)
s = list(input())
Q = int(input())
a = 0
b = 0
for i in range(Q):
    t = list(input().split())
    if t[0] == "1":
        a += 1
    if t[0] == "2":
        if (a + int(t[1])) %2 ==0:
            s.append(t[2])
        else:
            s.insert(0,t[2])
if a % 2 == 1:
    ans = "".join(reversed(s))
else:
    ans = s
print(ans)
S = list(input())
Q = int(input())
a = 0
b = 0
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    if len(S)>1:
      a += 1
      b += 1
    
  elif (q[1] == '1' and a%2 == 0) or (q[1] == '2' and a%2 == 1):
    S= [q[2]]+S
    a = 0
    
    
  else:
    S = S+[q[2]]
    a = 0
    
if b%2 == 1:
  S.reverse()
    
S="".join(S)
print(S)
s=input()
q=int(input())

rev=1

sf=[]
sb=[]

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf.append(n[2])
    else:
      sb.append(n[2])

s=''.join(sf)+s+''.join(sb)

if rev==1:
  print(s)
else:
  print(s[::-1])
S = input()
Q = int(input())
last = 0
for i in range(Q):
  q = input().split()
  if (last == 1 and q[0] == '1'):
    last = 0
  elif (last == 0 and q[0] == '1'):
    last = 1
  elif (last == 1 and q[1] == '1'):
    last = 0
    S = S[::-1]
    S = q[2] + S
  elif (last == 0 and q[1] == '1'):
    S = q[2] + S
  elif (last == 1 and q[1] == '2'):
    last = 0
    S = S[::-1]
    S += q[2]
  else:
    S += q[2]
print(S)
s = list(input())
q = int(input())

for _ in range(q):
    ql = list(input().split())
    if ql[0] == '1':
        s[0], s[-1] = s[-1], s[0]
    else:
        if ql[1] == '1':
            s.insert(0, ql[2])
        else:
            s.append(ql[2])

print(*s, sep='')
s = input()
q = int(input())
count = 0

for _ in range(q):
    Q = list(map(str, input().split()))
    if Q[0] == "1":
        count += 1
    else:
        if (int(Q[1])+count)%2 == 1:
            s = Q[2] + s
        else:
            s = s + Q[2]
        count = 0

if count%2 == 0:
    s = s[::-1]
print("".join(s))
s = input()
q = int(input())

query = [input() for _ in range(q)]
count = 0

#memo = [[]for _ in range(10**5)]
right = ""
left = ""
for qu in query:
    if len(qu.split()) == 1:
        count += 1
        right, left = left, right
        continue
    num, f, c = qu.split()
    num = int(num)

    if f == 1:
        left += c
        
    else:
        right += c

print(left[::-1] + s + right)
s=input()
q=int(input())
list=[input() for i in range(q)]
for i in list:
  i=i.split()
  if len(i)==1:
    s=s[::-1]
  else:
    if i[1]==1:
      s=i[2]+s
    else:
      s=s+i[2]

print(s)
s = str(input())
q = int(input())

for i in range(q):
    query = str(input())
    #前後を反転
    if query == '1' and len(s) > 1:
        s = s[len(s) - 1:] + s[1:len(s) - 1] + s[:1]
        continue

    querys = list(map(str, query.split()))
    #文字を付加
    if querys[1] == '1':
        s = querys[2] + s
    else:
        s = s + querys[2]
print(s)
import numpy as np
S = input()

Q = int(input())

A = [S]

for i in range(Q):
    s = input().split()
    if len(s) == 1:
        A = A[::-1]
    else:
        if s[1] == '1':
            A.insert(0,s[2])
        else:
            A.insert(-1,s[2])

print('%s' % ''.join(A))
left = input()
q = int(input())
right = ""
flag = 1
for i in range(q) :
    t = input()
    if t == "1" :
        flag ^= 1
        continue
    t, f, c = t.split(" ")
    f = int(f)
    left += c*flag*(2-f)
    right += c*flag*(f-1)
    left += c*(1-flag)*(f-1)
    right += c*(1-flag)*(2-f)
if flag == 1 :
    print(left[::-1]+right)
else :
    print(right[::-1]+left)
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

d=deque(S)
reverse=False
for q in query:
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if f=='1':
      d.appendleft(c) if reverse else d.append(c)
    else:
      d.append(c) if reverse else d.appendleft(c)
if reverse:
  print(*d,sep='')
else:
  d.reverse()
  print(*d,sep='')
S = list(input())
Q = int(input())

data = [list(map(str,input().split())) for _ in range(Q)]

A = []
B = []
a = 0

for i in range(Q-1,-1,-1):
  if data[i][0] == '1':
    a += 1
  else:
    if (int(data[i][1]) + a) % 2 == 1:
      A.append(data[i][2])
    else:
      B.insert(0,data[i][2])
      
if a % 2 == 1:
  for i in range(len(S)):
    S[i] = S[len(S)-1-i]

A.extend(S)
A.extend(B)

C = ''.join(A)

print(C)
s = input()
q = int(input())

query = [input() for _ in range(q)]

right = ""
left = ""
for qu in query:
    if len(qu.split()) == 1:
        right, left = left, right
        continue
    num, f, c = qu.split()
    f = int(f)

    if f == 1:
        left += c
        
    else:
        right += c

print(left[::-1] + s + right)
import math


def main():
    S = list(input())

    Q = int(input())

    for _ in range(Q):
        a = tuple(input().split())
        if a[0] == "2":
            if a[1] == "1":
                S.insert(0, a[2])
            else:
                S.append(a[2])
        else:
            S[0], S[-1] = S[-1], S[0]

    print("".join(S))

    return 0


if __name__ == '__main__':
    main()
import sys

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

re=False
for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        re= ~re
    else:
        if q_i[1]=="1" and re==True:
            s=[q_i[2]]+s
        elif q_i[1]=="2" and re==False:
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

if re==True:
    s=s[::-1]

s="".join(s)
print(s)
a=input()
q=int(input())
val=0
for i in range(q):
    b=input().split()
    if b[0]=="1":
        val+=1
    else:
        if b[1]=="1":
            if val%2==0:
                a=b[2]+a
            else:
                a+=b[2]
        else:
            if val%2==0:
                a+=b[2]
            else:
                a=b[2]+a
print(a)
import sys
from collections import deque
input = sys.stdin.readline

reverse = 0
S = deque(list(input()))
q = int(input())

for _ in range(q):
    query = input()
    if query[0] == '1':
        reverse = 1 - reverse
        continue

    _, f, c = query.split()
    f = int(f)
    action = (reverse + f) % 2
    if action:
        S.appendleft(c)
    else:
        S.append(c)

if reverse:
    S.reverse()
    
print(''.join(S))
s = input()
q = int(input())
flag = True
ans = [s]

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    flag = not flag
  else:
    if int(query[1]) == 1:
      if flag:
        ans.insert(0, query[2])
      else:
        ans.append(query[2])
    else:
      if flag:
        ans.append(query[2])
      else:
        ans.insert(0, query[2])

if flag:
  print("".join(ans))
else:
  ans.reverse()
  print("".join(ans))
s = []
s.append(input())
g = 0
q = int(input())
for i in range(q):
	d = input().split(" ")
	if d[0] == "1":
		if g == 0:
			g = 1
		else:
			g = 0
	if d[0] == "2":
		f = d[1]
		if g == 0:
			if f == "1":
				s.insert(0, d[2])
			else:
				s.append(d[2])
		else:
			if f == "1":
				s.append(d[2])
			else:
				s.insert(0, d[2])
if g == 1:
	s.reverse()
	ans = "".join(s)
	print(ans)
else:
	ans = "".join(s)
	print(ans)
from collections import deque
t=list(input().split())
s=deque(t)
q=int(input())
flag=True
for i in range(q):
  ques=list(input().split())
  if ques[0]=="1":
    flag=not flag
    continue
  if ques[1]=="1":
    if flag:
      s.appendleft(ques[2])
    else:
      s.append(ques[2])
  else:
    if flag:
      s.append(ques[2])
    else:
      s.appendleft(ques[2])
if flag==False:
    print(''.join(reversed(list(s))))
else:
    print(''.join(list(s)))
from collections import deque

s=deque(list(input()))
flag=True
for i in range(int(input())):
  dir=input().split()
  if int(dir[0])==1:flag=False
  else:
    if int(dir[1])==1:
      if flag:s.appendleft(dir[2])
      else:s.append(dir[2])
    else:
      if flag:s.append(dir[2])
      else:s.appendleft(dir[2])
s=list(s)
if flag==False:s.reverse()
print(*s,sep='')