peterverebics/CodeNet_Python_118 huggingface dataset:
s = input()
n = int(input())
head = ''
tail = s
for _ in range(n):
    q = input()
    if q[0] == '1':
        head, tail = tail, head
    else:
        _, f, c = q.split()
        if f == '1':
            head += c
        else:
            tail += c
print(head[::-1] + tail)
s = input()
q = int(input())

front = []
back = []
cnt = 0
for i in range(q):
    t = input()
    if t[0] == '1':
        cnt ^= 1
    else:
        f = 1 if int(t[2]) == 1 else 0
        c = t[4]
        if cnt ^ f:
            front.append(c)
        else:
            back.append(c)

ans = ''.join(front)[::-1] + s + ''.join(back)
print(ans[::-1] if cnt else ans)
s = input()
top = ''
n = int(input())
isReverse = False
for i in range(n):
    Q = input().split()
    if(Q[0] == '1'):
        isReverse = not isReverse
    else:
        if Q[1] == '1':
            if isReverse: s += Q[2]
            else: top += Q[2]
        else:
            if isReverse: top += Q[2]
            else: s += Q[2]
if isReverse: s = s[::-1] + top
else: s = top[::-1] + s
print(s)
s = list(input())
n = int(input())
head = []
tail = []

cnt = 0
for _ in range(n):
    li = list(input().split())
    if li[0] == '1':
        head, tail = tail, head
        cnt += 1
    else:
        if li[1] == '1':
            head += li[2]
        else:
            tail += li[2]

if cnt % 2 != 0:
    s = s[::-1]
    
ans = head[::-1] + s + tail
print(*ans , sep='')
s=input()
q=int(input())
f=0
l,r='',''
for i in range(q):
    a=list(input().split())
    if a[0]=='1':
        f+=1
    else:
        if (int(a[1])-1)^(f%2)==0:
            l+=a[2]
        else:
            r+=a[2]
if f%2==1:
    print(r[::-1]+s[::-1]+l)
else:
    print(l[::-1]+s+r)
a = list(raw_input())
b = []
q = input()
for _ in xrange(q):
    line = raw_input().split()
    if line[0] == "1":
        a, b = b, a
    elif line[1] == "1":
        b.append(line[2])
    else:
        a.append(line[2])
print ''.join(b[::-1] + a)
from collections import deque

s=deque(list(input()))
flag=0
for i in range(int(input())):
  dir=input().split()
  if int(dir[0])==1:flag+=1
  else:
    if int(dir[1])==1:
      if flag%2==0:s.appendleft(dir[2])
      else:s.append(dir[2])
    else:
      if flag%2==0:s.append(dir[2])
      else:s.appendleft(dir[2])
s=list(s)
if flag%2==1:s.reverse()
print(*s,sep='')
from collections import deque
s=deque(list(input()))
q=int(input())
r = False
for i in range(q):
    tmp = list(input().split(' '))
    if tmp[0]=='1':
        r = not r
    elif (not r and tmp[1]=='1') or (r and tmp[1] =='2'):
        s.appendleft(tmp[2])
    else:
        s.append(tmp[2])
if not r:
    for i in s:
        print(i,end='')
else:
    for i in reversed(s):
        print(i,end='')
S = input()
Q = int(input())

left = ''
right = S
for q in range(Q):
    Query = list(map(str, input().split()))
    if Query[0] == '1':
        #反転
        tmp = left
        left = right
        right = tmp
    else:   #Query[0]==2
        if Query[1] == '1':
            #先頭追加
            left += Query[2]
        else:   #Query[1] ==2
            #末尾追加
            right += Query[2]

ans = left[::-1] + right
print(ans)
S=input()
Q=int(input())
Query=[input().split() for i in range(Q)]

m=1
A=[]
B=[]
for i in range(Q):
  if int(Query[i][0])==1:
    m*=-1
  else:
    
    if m*((-2*int(Query[i][1]))+3)==1:
      A.append(Query[i][2])
    else:
      B.append(Query[i][2])
if m==1:
  print(''.join(A)[::-1]+S+''.join(B))
else:
  print(''.join(B)[::-1]+S[::-1]+''.join(A))
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)
if  x%2==1:
    S=S[::-1]
S=appends[x%2][::-1]+S+appends[(x+1)%2]
#print(S)
for k in S:
    print(k,end='')
from collections import deque

S = input()
Q = int(input())

ans = deque()
ans.append(S)
reverse = False

for i in range(Q):
    x = list(input().split())
    if int(x[0]) == 1:
        reverse = not reverse
        continue
    if int(x[1]) == 1 and not reverse:
        ans.appendleft(x[2])
    elif int(x[1]) == 2 and reverse:
        ans.appendleft(x[2])
    else:
        ans.append(x[2])

ans = ''.join(ans)

if reverse:
    print(ans[::-1])
else:
    print(ans)
from collections import deque

s = deque(input())
q = int(input())
rev = False

for _ in range(q):
    t = input()
    if t[0] == "2":
        _, f, c = t.split()
        if rev:
            if f == "2": s.appendleft(c)
            else: s.append(c)
        else:
            if f == "1": s.appendleft(c)
            else: s.append(c)
    else: rev = not rev

if rev: s.reverse()
print("".join(s))
string = input()
N=int(input())
Que = []
for i in range(N):
	Que.append(input())

init = ""
end = ""
rev = 2
for Q in Que:	
	if int(Q[0]) == 1:
		if rev != 1:
			rev=1
		else:
			rev=2
	elif int(Q[0])==2:
		T,F,C = Q.split(' ')
		if rev == 1:
			if int(F) == 1:
				F =2
			else:
				F = 1
		if int(F) == 1:
			init = init+C
		elif int(F) == 2:
			end = end + C
final = init[-1::-1]+string+end
if rev == 1:
	print(final[-1::-1])
else:
	print(init[-1::-1]+string+end)
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(list(reversed(''.join(q)))) if reverse else ''.join(q))


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

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    print(h[::-1] + s + t)
else:
    s = s[::-1]
    print(t[::-1] + s + h)
from collections import deque
D=deque(input().rstrip())
Q=int(input())
count=0
for _ in range(Q):
	Y=list(input().split())
	if Y[0]=="1":
		count=(count+1)%2
	else:
		if Y[1]=="1":
			if count==0:
				D.appendleft(Y[2])
			else:
				D.append(Y[2])
		else:
			if count==0:
				D.append(Y[2])
			else:
				D.appendleft(Y[2])
D=list(D)
if count==0:
	print("".join(D))
else:
	D.reverse()
	print("".join(D))
from collections import deque

s = deque((str(input())))
loop = int(input())

rev = 0
for i in range(loop):
    queries = input().split()
    if len(queries) == 1:
        rev = (rev+1) % 2
    else:
        type = int(queries[1])
        c = str(queries[2])
        if (type + rev) % 2 == 1:
            s.appendleft(c)
        else:
            s.append(c)
if rev == 1:
    s.reverse()
print("".join(list(s)))
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s = collections.deque(input())
Q = int(input())
for _ in range(Q):
  I = input()
  if len(I) == 1:
    count += 1
  else:
    F = int(I[2])
    C = I[4]
    k = (count + F ) % 2
    if k == 0:
      s.append(C)
    else:
      s.appendleft(C)
if count % 2:
  s.reverse()
for i in s:
  print(i,end = "")
print()
S = input()
Q = int(input())
arr1 = []
arr2 = []
count = 1
for _ in range(Q):
    q = input()
    if q == "1":
        count *= -1
    else:
        _, f, c = map(str, q.split())
        if f == "1":
            arr1.append(c) if count == 1 else arr2.append(c)
        else:
            arr2.append(c) if count == 1 else arr1.append(c)

if count == 1:
    ans = "".join(arr1[::-1]) + S + "".join(arr2)
else:
    ans = "".join(arr2[::-1]) + S[::-1] + "".join(arr1)
print(ans)
from collections import deque

s = input()
a = deque()
for i in s:
  a.append(i)
q = int(input())
rev = 0
for i in range(q):
  s = input()
  if s[0] == '1':
    rev ^= 1
  else:
    b = (int(s[2]) - 1) ^ rev
    if b:
      a.append(s[4])
    else:
      a.appendleft(s[4])
if rev:
  a.reverse()
for i in a:
  print(i, end="")
import collections
s = collections.deque(list(input()))
q = int(input())
cnt = 0
for i in range(q):
    fc = input().split()
    if fc[0] == '1':
        cnt += 1
    else:
        if cnt == 1:
            fc[1] = '1' if fc[1] == '2' else '2'
        if fc[1] == '1':
            s.appendleft(fc[2])
        else:
            s.append(fc[2])
    cnt %= 2
s = list(s)
if cnt == 1:
    s.reverse()
print(*s, sep='')
import collections
import sys

S=collections.deque(input())
Q=int(input())

r=0
for _ in range(Q):
    fs=next(sys.stdin).split()
    T=int(fs[0])
    if T==1:
        r^=1
    else:
        F,C=int(fs[1])-1,fs[2]
        if F==r:
            S.appendleft(C)
        else:
            S.append(C)

ans=''.join(reversed(S) if r else S)
print(ans)
A = input()
B = int(input())
C = ""
for i in range(B):
    D = input().split()
    if D[0] == "1":
        C,A = A,C
    else:
        if D[1] == "1":
            C += D[2]
        else:
            A += D[2]
C = C[::-1]
print(C+A)
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 0
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 0:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.appendleft(b[2])
if ans % 2 == 1:
  d.reverse()
print("".join(d))
S = input()
Q = int(input())
F,B = "",""
k = 1
for i in range(Q):
    q = list(input().split())
    if int(q[0])==1:k = abs(k-1)
    else:
        if int(q[1])==1:
            if k:F+=q[2]
            else:B+=q[2]
        else:
            if k:B+=q[2]
            else:F+=q[2]
if k:print(F[::-1]+S+B)
else:print(B[::-1]+S[::-1]+F)
from collections import deque
S = deque()
tmp = input()
for i in range(len(tmp)):
  S.append(tmp[i])
Q = int(input())
flag = True
for i in range(Q):
  string = input().split()
  if string[0] == '1':
    flag = not flag
  elif flag ^ (string[1] == '1'):
      S.append(string[2])
  else:
      S.appendleft(string[2])
if not flag:
  S.reverse()
for s in S:
  print(s, end='')
def main():
    s = input()
    n = int(input())
    pre = ''
    suf = ''
    r = 1
    for _ in range(n):
        q = input().split()
        if len(q) == 1:
            r *= -1
            continue
        if r * int(q[1]) in (1, -2):
            pre = q[2] + pre
        else:
            suf += q[2]
    ans = pre + s + suf
    if r == -1:
        ans = ans[::-1]
    print(ans)


if __name__ == '__main__':
    main()
from collections import deque
S = deque(input())
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S.append(I[2])
    else:
      S.appendleft(I[2])
if d == 1:
  S.reverse()
for s in S:
  print(s, end="")
print()
from collections import deque
S = deque(input())
Q = int(input())
q = [input().split() for _ in range(Q)]
flag = True
for x in q:
    if x[0] == "1":
        if flag: flag = False
        else: flag = True
    else:
        if x[1] == "1":
            if flag: S.appendleft(x[2])
            else: S.append(x[2])
        else:
            if flag: S.append(x[2])
            else: S.appendleft(x[2])
s = list(S)
if not flag: s = s[::-1]
print("".join(s))
from collections import deque
import sys
input=sys.stdin.readline
s=deque([input().rstrip()])
q=int(input())
rev=0
for _ in range(q):
	qw=input().split()
	if qw[0]=="1":
		rev+=1
	else:
		f=qw[1]
		c=qw[2]
		if f=="1":
			if rev%2==0:
				s.appendleft(c)
			else:
				s.append(c)
		else:
			if rev%2==0:
				s.append(c)
			else:
				s.appendleft(c)
ans=""
for x in s:
	ans+=x
if rev%2==0:
	print(ans)
else:
	print(ans[::-1])
from collections import deque
f=input
s=deque(f())
n=int(f())
t=0
for i in range(n):
  q=f()
  if q[0]=='1': t=1-t
  elif int(q[2])+t==2: s.append(q[4])
  else: s.appendleft(q[4])
print(''.join([s,list(s)[::-1]][t]))
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)
S = list(input())
Q = int(input())
A = []
a = 0
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    a += 1
  else:
    if (q[1] == '1' and a % 2 == 0) or (q[1] == '2' and a % 2 == 1):
      A.append(q[2])
    else:
      S.append(q[2])
A = A[::-1]
S = A + S
if a % 2 == 1:
  S = S[::-1]
ans = ''.join(S)
print(ans)
s = input()
sgn = 1
Q = int(input())
L = '' #sgn=-1
R = '' #sgn=1
for _ in range(Q):
  i = input()
  if i[0] == '1':
    sgn*=-1
  else:
    if i[2] == '1':
      if sgn == 1:
        L += i[4]
      else:
        R += i[4]
    else:
      if sgn == 1:
        R += i[4]
      else:
        L += i[4]

if sgn == -1:
  s = s[::-1]
  R = R[::-1]
  print(R + s +L)
  
else:
  L = L[::-1]
  print(L + s + R)
S = input()
Q = int(input())
t = ''
for i in range(Q):
  instructions = list(map(str, input().split()))
  if instructions[0] == '1':
    S, t = t, S
  else:
    if instructions[1] == '1':
      t += instructions[2]
    else:
      S += instructions[2]
print(t[::-1] + S)
S = input()
lQ = list(range(int(input())))
def main(S):
  T = True
  L = ''
  R = ''
  for i in lQ:
    q = list(input().split())
    if q[0]=='1':
      T = not(T)
    else:
      if (T and q[1]=='1') or (not(T) and q[1]=='2'):
        L += q[2]
      elif (T and q[1]=='2') or (not(T) and q[1]=='1'):
        R += q[2]
  SS = L[::-1] + S + R
  if T:
    print(SS)
  else:
    print(SS[::-1])
main(S)
S = input()
Q = int(input())

r = False
prefix = []
suffix = []
for _ in range(Q):
    query = input()
    if query == '1':
        r ^= True
    else:
        _, f, c = query.split()
        front = f == '1'

        if r ^ front:
            prefix.append(c)
        else:
            suffix.append(c)

if r:
    S = ''.join(suffix[::-1]) + S[::-1] + ''.join(prefix)
else:
    S = ''.join(prefix[::-1]) + S + ''.join(suffix)

print(S)
s=input()
n=int(input())
rev=1
pre=''
suf=''

for i in range(n):
  q=input().split()
  if q[0]=='1':
    rev+=1
  elif (rev+int(q[1]))%2==0:
    pre=q[2]+pre
  else:
    suf=suf+q[2]
    
ans=pre+s+suf
  
if rev%2==0:
  print(ans[::-1])
else:
  print(ans)
from collections import deque

S = input()
Q = int(input())
W = 0
ans = deque(list(S.rstrip()))

for _ in range(Q):
#    print(W,ans)
    qry = list(input().rstrip().split())
    if qry[0] == "1":
        W = 1-W
        continue
    T,F,C = qry
    C.rstrip()
    if (W == 0 and F=="2") or (W==1 and F=="1"):
        ans.append(C)
    else:
        ans.appendleft(C)
ans = "".join(map(str,ans))
if W == 1:
    ans = ans[::-1]
print(ans)
s = list(input())
q = int(input())
judge = 1
front = []
back = []
for i in range(q):
  a = list(map(str,input().split()))
  if int(a[0]) == 1:
    judge *= -1
  else:   
    if (int(a[1]) == 1 and judge == 1) or (int(a[1]) == 2 and judge == -1):
      front.append(a[2])
    else:
      back.append(a[2])
ans = front[::-1] + s + back
if judge == -1:
  ans.reverse()
print(*ans, sep='')
S = input()
Q = int(input())

T = ""
for i in range(Q) :
    Query = list(input().split())
    if Query[0] == "1" :
        S, T = T, S
    elif Query[0] == "2" :
        if Query[1] == "1" :
            T = T + Query[2]
        elif Query[1] == "2" :
            S = S + Query[2]

T = T[::-1]
T = T + S
print(T)
from collections import deque

s = list(input())
q = int(input())
query = [list(input().split()) for i in range(q)]
now = 0
a = deque(s)
for i in query:
  if i[0] == "1":
    now ^= 1
  elif i[0] == "2":
    f,c = int(i[1]),i[2]
    if (f+now) % 2:
      a.appendleft(c)
    else:
      a.append(c)
if now:
  a.reverse()
ans = "".join(a)
print(ans)
from collections import deque
S = input()
Q = int(input())
li = []
for i in range(Q):
    li.append(list(input().split()))
flag = False
sq = deque(S)
for i in range(Q):
    if li[i][0] == "1":
        flag = not flag
    else:
        if (li[i][1] == "1" and not flag) or (li[i][1] == "2" and flag):
            sq.appendleft(li[i][2])
        else:
            sq.append(li[i][2])
sq = list(sq)
if flag:
    sq.reverse()
for i in range(len(sq)):
    print(sq[i], end="")
import sys
S = input()
A = ''
input()
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            A = A + i[4]
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            A = A + i[4]
        else:
            S = S + i[4]

ans = A[::-1] + S
print(ans[::key])
from collections import deque
s = input()
q = int(input())
r = False
S = deque(s)
for _ in range(q):
  d = list(input().split())
  if len(d)==1:
    r = ~r
  else:
    if (d[1]=='1' and ~r) or (d[1]=='2' and r):
      S.appendleft(d[2])
    else:
      S.append(d[2])
s = ''.join(S)
if r:
  s = s[::-1]
print(s)
import collections
s = collections.deque(list(input()))
q = int(input())
cnt = 0
for i in range(q):
    fc = input().split()
    if fc[0] == '1':
        cnt += 1
    else:
        if cnt == 1:
            fc[1] = '1' if fc[1] == '2' else '2'
        if fc[1] == '1':
            s.appendleft(fc[2])
        else:
            s.append(fc[2])
    cnt %= 2
if cnt == 1:
    s.reverse()
print(*s, sep='')
s = list(input())
q = int(input())
a = []
f = False #さかさま
for i in range(q):
    x = list(input().split())
    if x[0]=='1':
        f = not f
    else:
        if f:
            if x[1]=='1': s.append(x[2])
            else: a.append(x[2])
        else:
            if x[1]=='1': a.append(x[2])
            else: s.append(x[2])
a.reverse()
s = a+s
if f:s.reverse()
print(''.join(s))
s=input()
q=int(input())
cnt=0 #反転の回数の偶奇を記憶
right=""
left=""
for i in range(q):
	query=list(input().split())
	if query[0]=="1":
		cnt+=1
	else:
		if (cnt+int(query[1]))%2==0:
			right+=query[2]
		else:
			left+=query[2]
if cnt%2==0:
	print(left[::-1]+s+right)
else:
	print(right[::-1]+s[::-1]+left)
s=input()
q=int(input())
cnt=0
front=[]
rear=[]
for qq in range(q):
  l=list(input().split())
  if l[0]=='1':
    cnt+=1
  else:
    if (cnt+int(l[1]))%2==1:
      front.append(l[2])
    else:
      rear.append(l[2])
front=''.join(front[::-1])
rear=''.join(rear)
s=front+s+rear
print(s if cnt%2==0 else s[::-1])
string = input()
kai = int(input())
data = [input().split(' ') for i in range(kai)]
key = 0  #0 start
former = []
latter = []

for i in range(kai):
    if(data[i][0] == '1'):
        key = (key + 1) % 2
    elif((int(data[i][1]) + key) % 2 == 1):
        former.append(data[i][2])
    else:
        latter.append(data[i][2])

string = ''.join(former[::-1]) + string + ''.join(latter)
if(key == 0):
    print(string)
else:
    print(string[::-1])
import sys
s = input()
q = int(input())
a = ['', '']
r = 0
for l in sys.stdin:
    if l[0] == '1':
        r ^= 1
    else:
        a[0 if l[2] == '21'[r] else 1] += l[4]
if r:
    print(a[0][::-1] + s[::-1] + a[1])
else:
    print(a[1][::-1] + s + a[0])
S = list(str(input()))
Q = int(input())

state = 0
start = []
end = []

for i in range(Q):
    x = list(input().split())
    if x[0] == "1":
        state = (state+1)%2
    else:
        x[1] = int(x[1])
        if (state + x[1]) % 2 == 1:
            start.append(x[2])
        else:
            end.append(x[2])

if state == 0:
    start.reverse()
    ans = start + S + end
    
else:
    end.reverse()
    S.reverse()
    ans = end + S + start

print("".join(ans))
right = input()
q = int(input())
left = ""
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)
s = input()
q = int(input())

sg = 1
fr = []
ba = []
for x in range(q):
  query = [s for s in input().split()]
  if query[0] == '1':
    sg *= -1
  else:
    if int(query[1])*2 + sg == 3:
      fr.append(query[2])
    else:
      ba.append(query[2])

if sg == 1:
  fr.reverse()
  frn = ''.join(fr)
  ban = ''.join(ba)
  print(frn + s + ban)
else:
  ba.reverse()
  frn = ''.join(fr)
  ban = ''.join(ba)
  print(ban + ''.join(list(reversed(s))) + frn)
s=input()
q=int(input())
que=[list(map(str,input().split())) for i in range(q)]
count=0
for i in que:
  if i[0]=="1":
    count+=1
ans=[[],[]]
ak=count
for i in que:
  if i[0]=="1":
    count-=1
  else:
    if i[1]=="1":
      ans[count%2].append(i[2])
    else:
      ans[(count+1)%2].append(i[2])
if ak%2==0:
  print("".join(reversed(ans[0]))+s+"".join(ans[1]))
else:
  print("".join(reversed(ans[0]))+"".join(reversed(list(s)))+"".join(ans[1]))
from collections import deque
S = input()
q = deque()
for s in list(S):
    q.append(s)
Q = int(input())
direction = True
for _ in range(Q):
    line = input()
    if line[0] == '1':
        direction = not direction
    else:
        if (direction and line[2] == '1') or (not direction and line[2] == '2'):
            q.appendleft(line[4])
        else:
            q.append(line[4])
print("".join(q) if direction else "".join(reversed(q)))
from collections import deque

s = list(input())
q = int(input())
t = [list(map(str,input().split())) for _ in range(q)]

d = deque(s)

cnt = 0
for i in range(q):
  if len(t[i]) == 1:
    cnt += 1
  else:
    if (int(t[i][1])+cnt) % 2 != 0:
      d.appendleft(t[i][2])
    else:
      d.append(t[i][2])
      
if cnt%2 != 0:
  d = list(d)[::-1]
print(''.join(d))
from collections import deque

S = input()
Q = int(input())
L = 1
S = deque(S)

for i in range(Q):
    A = list(input().split())
    if int(A[0]) == 1:
        L = -L
    if int(A[0]) == 2:
        A[1] = 2*int(A[1]) - 3
        if L*A[1] == -1:
            S.appendleft(A[2])
        else:
            S.append(A[2])

if L == 1:
    print(''.join(S))
else:
    print(''.join(list(reversed(S))))
s = list(input())
q = int(input())
front = []
end = []
flip = False
for i in range(q):
    x = input()
    if x == "1":
        flip = flip ^ True
    else:
        z,f,c = x.split()
        f = bool(int(f)-1)
        if flip ^ f:
            end.append(c)
        else:
            front.append(c)
if flip:
    s = s[::-1]
    ans = end[::-1] + s + front
else:
    ans = front[::-1] + s + end
print("".join(ans))
from collections import deque
import sys
input = sys.stdin.readline
s = str(input().rstrip())
ans = deque(list(s))

f = True
q = int(input())
for i in range(q):
    q = list(map(str, input().split()))
    if int(q[0]) == 1:
        f = not f
    else:
        f_i = int(q[1])
        if (f_i == 1) ^ f:
            ans.append(q[2])
        else:
            ans.appendleft(q[2])
ans = "".join(list(ans))
if not f:
    ans = ans[::-1]
print(ans)
from collections import deque

S = input()
Q = int(input())

cur = 1
d = deque([S])

for _ in range(Q):
    ins = input().split()
    if len(ins) == 1:
        cur = 2 if cur == 1 else 1
    else:
        _, f, c = ins
        f = int(f)
        if cur == f == 1 or cur == f == 2:
            d.appendleft(c)
        else:
            d.append(c)

if cur == 1:
    print("".join(d))
else:
    temp = "".join(d)
    print(temp[::-1])
import sys
#input=sys.stdin.readline
from collections import deque

r=False
d=deque(list(input()))
for i in range(int(input())):
  Q=input().split()
  if Q[0]=='1':
    r=not r
  else:
    if (Q[1]=='1' and not r) or (Q[1]=='2' and r):
      d.appendleft(Q[2])
    else:
      d.append(Q[2])

if r:
  d.reverse()

print("".join(list(d)))