peterverebics/CodeNet_Python_118 huggingface dataset:
from collections import deque
S=deque(input())
Q=int(input())
reverse=0
for q in range(Q):
    Query=list(input().split())
    T=Query[0]
    if T=="1":
        reverse+=1
    if T=="2":
        F,C=Query[1],Query[2]
        if F=="1" and reverse%2==0 or F=="2" and reverse%2==1:
            S.appendleft(C)
        else:
            S.append(C)
S="".join(S)
print(S if reverse%2==0 else S[::-1])
from collections import deque
s=deque(input())
q=int(input())
flag = 2

for i in range(q):
    query=input().split()
    if query[0] == "1":
        flag = 3 - flag
    elif int(query[1]) - flag :
         s.appendleft(query[2])
    else:
        s.append(query[2])

if flag-2:
    s.reverse()

print("".join(s))
S=input()
n=int(input())
t=0
L=""
R=""
for i in range(n):
    Q=list(input().split())
    if Q[0]=="1":
        if t==0:
            t=1
        else:
            t=0
    else:
        if int(Q[1])+t==2:
            R=R+Q[2]
        else:
            L=Q[2]+L
            
ans=L+S+R
if t==0:
    print(ans)
else:
    print(ans[::-1])
from collections import deque
import sys
read = sys.stdin.readline

s = deque(read().rstrip())
q = int(read())

rev = 0
for _ in range(q):
    a = tuple(read().split())
    if a[0] == '1':
        rev ^= 1
    else:
        dir = rev ^ int(a[1]) - 1
        if dir == 0:
            s.appendleft(a[2])
        else:
            s.append(a[2])

if rev:
    print(''.join(s)[::-1])
else:
    print(''.join(s))
s=input()
n=int(input())
a=[input() for _ in range(n)]

front=True
f=""
b=""

for q in a:
    if q=="1":front=not front;continue
    l=q.split()
    if l[1]=="1":
        if front:f=l[2]+f
        else:b=b+l[2]
    if l[1]=="2":
        if front:b=b+l[2]
        else:f=l[2]+f

print(f+s+b if front else (f+s+b)[::-1])
s = list(str(input()))
q = int(input())
f = []
b = []
cnt = 0
for i in range (q):
    t = list(str(input()))
    if t[0] == '2':
        if t[2] == '1':
            f.append(t[4])
        else:
            b.append(t[4])
    else:
        x = f
        y = b
        f = y
        b = x
        cnt += 1
f.reverse()
if cnt%2 != 0:
    s.reverse()
    
print(''.join(f) + ''.join(s) + ''.join(b))
import sys
from collections import deque


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

for query in sys.stdin:
    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_number = int(input())
reverse_flag = 1
head = ""
tail = ""
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    headstails = int(temp[1])*reverse_flag 
    if headstails == 1 or headstails == -2:
      head = temp[2] + head
    else:
      tail = tail + temp[2]
      
if reverse_flag == 1:
  print(head+s+tail)
else:
  print(tail[::-1]+s[::-1]+head[::-1])
from collections import deque

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

rev = False

for _ in range(Q):
    T, F, C, *_ = input().split() + [None, None]

    if int(T) == 1:
        rev = not rev
    else:
        F = int(F)
        if rev:
            F = F % 2 + 1

    if F == 1:
        S.appendleft(C)
    else:
        S.append(C)

if rev:
    S.reverse()

print(*[x for x in S if x], sep='')
from collections import deque

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

queue = deque(list(S))

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

        if r ^ front:
            queue.appendleft(c)
        else:
            queue.append(c)

if r:
    ans = ''.join(list(queue)[::-1])
else:
    ans = ''.join(queue)

print(ans)
from collections import deque

s = deque(input())
q = int(input())
flip = 0
for _ in range(q):
    com, *query = input().split()
    if com == "1":
        flip ^= 1
    else:
        f, c = query
        f = int(f)-1
        if f ^ flip == 1:
            s.append(c)
        else:
            s.appendleft(c)
s = "".join(s)
print(s if not flip else s[::-1])
from collections import deque
 
S = deque(input())
Q = int(input())
 
Q_list = [list(map(str, input().split())) for i in range(Q)]
 
rev = False
 
for i in range(Q):
  if int(Q_list[i][0]) == 1:
    rev = not rev
  
  else:
    F = Q_list[i][1]
    C = Q_list[i][2]
    
    if rev ^ (int(F) == 1): # 排他的論理和片方真片方ぎの時真になる
      S.appendleft(C)
    else:
      S.append(C)
      
if rev:
  S.reverse()
  
print(''.join(S))
from collections import deque

S = input()

q = deque(S)
forward = True
for _ in range(int(input())):
    TFC = input().split()
    if TFC[0] == '1':
        forward = not forward
    else:
        if (TFC[1] == '1') == forward:
            q.appendleft(TFC[2])
        else:
            q.append(TFC[2])

if not forward:
    q.reverse()

print(''.join(q))
B = input()
order = True
F = ""
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        order ^= True
    else:
        f,c = T[1],T[2]
        if not((f == "1") ^ order):
            F += c
        else:
            B += c
    #print(F,B)
F = F[::-1]+B
if not order:
    F = F[::-1]
print(F)
from collections import deque

s = deque(input())
q = int(input())
is_reversed = False
for i in range(q):
    query = input().split()
    if query[0] == '1':
        is_reversed = not is_reversed
    elif (query[1] == '2') ^ is_reversed:
        s.append(query[2])
    else:
        s.appendleft(query[2])
if is_reversed:
    s.reverse()
print(''.join(s))
s,_,*q=open(0)
a='S'
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:a+=c
    else:a=c+a
  except:p^=1
print(a.replace('S',s[:-1])[::p or-1])
S = input()
Q = int(input())
r = False
F = []
B = []
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    if r:
      r = False
    else:
      r = True
  else:
    if (q[1] == '1' and not r) or (q[1] == '2' and r):
      F.append(q[2])
    else:
      B.append(q[2])

if r:
  print(''.join(B[::-1]+list(reversed(S))+F))
else:
  print(''.join(F[::-1]+list(S)+B))
from collections import deque

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

que = deque(s)

flipped = False
for i in range(q):
    query = input()
    if query[0] == "1":
        flipped = not flipped
    else:
        t, f, c = query.split()
        if (f == "1") ^ flipped:
            que.appendleft(c)
        else:
            que.append(c)
s = "".join(que)
if flipped:
    s = s[::-1]
print(s)
s = input()
q = int(input())
flag = False
l = ''
r = ''
for _ in range(q):
  Q = input().split()
  if Q[0] == '1':
    flag = not flag
  else:
    if flag:
      if Q[1] == '1':
        r += Q[2]
      else:
        l += Q[2]
    else:
      if Q[1] == '1':
        l += Q[2]
      else:
        r += Q[2]
if flag:
  print(''.join(reversed(r)), ''.join(reversed(s)), l, sep='')
else:
  print(''.join(reversed(l)), s, r, sep='')
s = input()
q = int(input())
c = 0
l = []
r = []

for i in range(q):
  query = input()
  if query[0] == "1":
    c += 1
    a = l
    l = r
    r = a
  if query[0] == "2":
    if query[2] == "1":
      l.append(query[4])
    if query[2] == "2":
      r.append(query[4])
      
l = "".join(l)
l = l[::-1]
r = "".join(r)
      
if c%2 == 1:
  s = s[::-1]
  
print(l + s + r)
from collections import deque

que=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 (f=='1' and rev==False) or (f=='2' and rev):
                  que.appendleft(c)
            else:
                  que.append(c)
if rev:
      que.reverse()
print(''.join(que))
from collections import deque
S = deque(list(input()))
Q = int(input())

flag = False
for _ in range(Q):
  query = input().split()
  if query[0] == '1':
    flag = not flag
  elif query[0] == '2':
    left = query[1] == '1'
    if flag:
      left = not left
    if left:
      S.appendleft(query[2])
    else:
      S.append(query[2])

if flag:
  print(''.join(reversed(S)))
else:
  print(''.join(S))
from collections import deque
s=input()
q=int(input())

flug=0
ans=deque(list(s))

for i in range(q):
    t=list(input().split())

    if t[0]=="1":
        flug+=1
    else:
        if (flug%2==0 and t[1]=="2") or (flug%2==1 and t[1]=="1"):
            ans.append(t[2])
        else:
            ans.appendleft(t[2])

ans="".join(map(str,ans))

if flug%2==1:
    ans=ans[::-1]
print(ans)
from collections import deque
s=deque(input())
f=False
for _ in range(int(input())):
  t=list(input().split())
  if t[0]=='1':
    if f is False:
      f = True
    else:
      f = False
  else:
    if t[1]=='1':
      if f is False:
      	s.appendleft(t[2])
      else:
        s.append(t[2])
    else:
      if f is False:
      	s.append(t[2])
      else:
        s.appendleft(t[2])
x=''.join(map(str,s))
if f is False:
	print(x)
else:
  print(x[::-1])
s = input()
q = int(input())
a, b = '', ''
cnt = 0
for _ in range(q):
    que = input().split()
    if que[0] == '1':
        cnt += 1
    else:
        if (cnt+int(que[1])) %2 == 0:
            a += que[2]
        else:
            b += que[2]
if cnt%2 == 1:
    s = a[-1::-1]+s[-1::-1]+b
else:
    s = b[-1::-1]+s+a
print(s)
s = input()
q = int(input())
turn = 0
# ともにSに近い方から並べる
before = "" 
after = ""
for _ in range(q):
    tmp = input()
    if tmp=="1":
        turn += 1
    else:
        _,f,c = tmp.split()
        f = int(f)
        if (turn + f) % 2 == 1:
            before += c
        else:
            after += c
if turn%2==0:
    out = before[::-1] + s + after
else:
    out = after[::-1] + s[::-1] + before
print(out)
from collections import deque

deq=deque()
k = input()
for i in range(len(k)):
	deq.append(k[i])
q=int(input())
x=True
for i in range(q):
	a=input()
	if a[0]=="1":
		x = not x
	elif a[2]=="1":
		if x==True:
			deq.appendleft(a[4])
		else:
			deq.append(a[4])
	else:
		if x==True:
			deq.append(a[4])
		else:
			deq.appendleft(a[4])
if x==True:
	c="".join(deq)
else:
	deq.reverse()
	c="".join(deq)
print(c)
S = input()
Q = int(input())
reverse = False
front = ""
end = ""
 
for i in range(Q):
    inp = input()
    if inp[0] == "1":
        reverse = not reverse
    else:
        _, F, C = inp.split()
        if (F == "1") ^ reverse:
            front = front+C
        else:
            end = end+C
if reverse:
    print(end[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+end)
s=input()
count=0
s1=str()
s2=str()
for _ in range(int(input())):
  l=list(map(str,input().split()))
  
  if l[0]=='1':
    count+=1
  elif count%2==0:
    if l[1]=='1':
      s1=l[2]+s1
    else:
      s2=s2+l[2]
  else:
    if l[1]=='2':
      s1=l[2]+s1
    else:
      s2=s2+l[2]
s=s1+s+s2
if count%2!=0:
  s=s[::-1]
print(s)
S=input()
Q=int(input())
inv = 0
s0 = ""
s1 = ""
for i in range(Q):
  q = input()
  if q[0] == "1":
    if inv == 0: inv = 1
    else: inv = 0
  else:
    q,f,c = q.split()
    if f == "1":
      if inv == 0:
        s0 += c
      else:
        s1 += c
    else:
      if inv == 1:
        s0 += c
      else:
        s1 += c
if inv == 1:
  S = s1[::-1] + S[::-1] + s0
else:
  S = s0[::-1] + S + s1

print(S)
from collections import deque
s=input()
q=int(input())
t=[input() for i in range(q)]
l=deque(list(s))
m=0
for i in range(q):
  if int(t[i][0])==1:
    m+=1
  else:
    if m%2==0:
      if int(t[i][2])==1:
        l.appendleft(t[i][4]) 
      else:
        l.append(t[i][4])
    else:
      if int(t[i][2])==2:
        l.appendleft(t[i][4]) 
      else:
        l.append(t[i][4])
if m%2==1:
  l.reverse()
print(''.join(l))
s = input()
q = int(input())
flag = 1
f = ''
b = ''
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    flag *= -1
  else:
    if flag == 1:
      if query[1] == '1':
        f += query[2]
      else:
        b += query[2]
    else:
      if query[1] == '1':
        b += query[2]
      else:
        f += query[2]
ans = f[::-1] + s + b
if flag == -1:
  ans = ans[::-1]
print(ans)
S = input()
Q = int(input())
A = [input().split() for i in range(Q)]

tmp = 0
s = S
t = ''

for li in A:
#     print(s,t,tmp)
    if li[0] == '1':
        tmp = (tmp+1)%2
    else:
        if (tmp+int(li[1]))%2 == 1:
            t += li[2]
        else:
            s += li[2]
            
if tmp == 0:
    print(t[::-1]+s)
else:
    print(s[::-1]+t)
from collections import deque
s = input()
q = int(input())
que = deque([s])
flg=False
for _ in range(q):
    a = list(input().split())
    if a[0]=='1':
        flg=not(flg)
#        s=s[::-1]
    else:
        if flg ^ (a[1]!='1'):
            que.append(a[2])
        else:
            que.appendleft(a[2])

ans = ''.join(que)

if flg:
    ans = ans[::-1]
print(ans)
t=list(input())
q=int(input())
s=[]

for i in range(q):
  query=list(input().split())
  if query[0]=='1':
    s,t=t,s
  else:
    if query[1]=='1':
      s.extend(query[2])
    else:
      t.extend(query[2])
if s==[]:
  s=t
else:
  s.reverse()
  s.extend(t)

moji=''.join(s)
print(moji)
from collections import deque

d = deque(list(input()))
flag = 1
for _ in range(int(input())):
    a = input()
    if a[0] == '1':
        flag *= -1
    elif a[2] == '1' and flag == 1:
        d.appendleft(a[4])
    elif a[2] == '1' and flag == -1:
        d.append(a[4])
    elif a[2] == '2' and flag == 1:
        d.append(a[4])
    else:
        d.appendleft(a[4])
if flag == -1:
    d.reverse()
print(''.join(d))
from collections import deque


S = deque(input())
Q = int(input())
is_reversed = False

for _ in range(Q):
    Query = input().split()
    if Query[0] == "1":
        is_reversed = not is_reversed
    else:
        F, C = int(Query[1]), Query[2]
        if is_reversed:
            F = 3 - F
        if F == 1:
                S.appendleft(C)
        else:
                S.append(C)

if is_reversed:
    S.reverse()
print("".join(S))
import collections
q = collections.deque(list(raw_input()))
operations = [raw_input().split(' ') for _ in range(int(raw_input()))]
rev = False

for op in operations:
	if len(op) == 1:
		rev = not(rev)
	elif len(op) == 3:
		_, where, char = op
		where = bool(int(where) - 1) ^ rev
		if where:			
			q.append(char)
		else:
			q.appendleft(char)

print ''.join(list(q)[:: (-1 if rev else 1)])
s=input()
q=int(input())
trans=0
aft=""
bef=""
for i in range(q):
  que=input()
  if que[0]=="1":
    trans=1-trans
  else:
    if (que[2]=="1" and trans==0) or (que[2]=="2" and trans==1):
      bef=bef+que[4]
    else:
      aft=aft+que[4]
if trans==0:
  print("".join(bef[::-1])+s+"".join(aft))
else:
  print("".join(aft[::-1])+s[::-1]+"".join(bef))
from collections import deque
d = deque()
d.extend(input())
q = int(input())
r = False
for i in range(q):
  qu = input().split()
  if qu[0] == "1":
    r = not r
  else:
    if (qu[1] == "1" and not r) or (qu[1] == "2" and r):
      d.extendleft(qu[2])
    else:
      d.extend(qu[2])

if r:
  d.reverse()

print(''.join(list(d)))
S = input()
numQ = int(input())
lead = 1
front = ""
rear = ""
for i in range(numQ):
  Q = input()
  if Q[0] == "1":
    lead *= -1
  else:
    if Q[2] == "1":
      if lead == 1:
        front = Q[4] + front
      else:
        rear = rear + Q[4]
    else:
      if lead == 1:
        rear = rear + Q[4]
      else:
        front = Q[4] + front
S = front + S + rear
if lead == -1:
  S = S[::-1]

print(S)
from collections import deque

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

rev=0
for i in range(q):
  l=input().split()
  if len(l)==1:
    rev+=1
  else:
    t,f,c=l[0],l[1],l[2]

    if rev%2==0:
      if f=='1':
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if f=='1':
        s.append(c)
      else:
        s.appendleft(c)

if rev%2==1:
  s.reverse()
print(''.join(s))
from collections import deque

S = deque(input())
queryNum = input()
flip = False
for i in range(int(queryNum)):
	order = input()
	if order == '1':
		if flip:
			flip = False
		else:
			flip = True
	else:
		if order[2] == '1':
			if not flip:
				S.appendleft(order[4])
			elif flip:
				S.append(order[4])
		else:
			if not flip:
				S.append(order[4])
			elif flip:
				S.appendleft(order[4])
S = ''.join(S)
if flip:
	print(S[::-1])
else: 
	print(S)
from collections import deque
S = deque(input())
Q = int(input())

p = 0

for i in range(Q):
    query = input().split()
    if query[0]=='1':
        p ^= 1
    else:
        f = int(query[1])-1
        c = query[2]
        if p:
            f ^= 1
        if f:
            S.append(c)
        else:
            S.appendleft(c)

if p:
    print(*reversed(S), sep='')
else:
    print(*S, sep='')
S = input()
Q = int(input())
rev = 1
head = []
tail = []
for _ in range(Q):
    lst = input().split() 
    if (lst[0] == '1'):
        rev *= -1
    else:
        if (lst[1] == '1'):
            pos = rev
        else:
            pos = -1 * rev
        if (pos == 1):
            head.append(lst[2])
        else:
            tail.append(lst[2])
ans = ''.join(head[::-1]) + S + ''.join(tail)
print(ans[::rev])
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

s = input()
q = ni()
f = 0
top = ''
bot = ''
for _ in range(q):
    w = input().split()
    if w[0] == '1':
        f ^= 1
        top,bot = bot,top
    elif w[1] == '1':
        top += w[2]
    else:
        bot += w[2]
print(top[::-1] + s[::1-f*2] + bot)
def resolve():
    s = input()
    query = int(input())
    r = 0
    left = ''
    for i in range(query):
        q = input()
        if q[0]=='2':
            _,f,c = q.split()
            if (int(f)+r)%2 == 0:
                s += c
            else:
                left += c
        else:
            r = (r+1)%2
    print(left[::-1]+s if r==0 else s[::-1]+left)
resolve()
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 1
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
if ans % 2 == 0:
  d.reverse()
print("".join(d))
from collections import deque
s = deque(input())
q = int(input())
state = 0
for i in range(q):
    query = input().split()
    if query[0] =="1":
        state +=1
    else:
        if (int(query[1])+state)%2 == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])
if state%2 == 1:
    s.reverse()
print("".join(s))
import sys
from collections import deque
def main():
  S = input()
  Q = int(input())
  r = False
  ans = deque(S)
  for l in sys.stdin:
    TFC = l.split()
    if TFC[0]=="1": r = not r
    elif TFC[1]=="1":
      if r: ans.append(TFC[2])
      else: ans.appendleft(TFC[2])
    elif TFC[1]=="2":
      if r: ans.appendleft(TFC[2])
      else: ans.append(TFC[2])
  print("".join(reversed(ans) if r else ans))

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

S = input()
Q = int(input())
s = deque(list(S))
re = False
 
for i in range(Q):
    q = list(map(str,input().split()))
    if q[0] == "1":
        re = not re
    else:
        b = int(q[1])-1
        if (re and b) or not(re or b):
            s.appendleft(q[2])
        else:
            s.append(q[2])
 
ans = ""
if re:
    while s:
    	ans += s.pop()
else:
    while s:
        ans += s.popleft()
print(ans)
def main():
  S = input()
  Q = int(input())
  Queries = [input().split() for i in range(Q)]
  #print(Queries)
  is_reversed = False
  prefix = ''
  suffix = ''
  for Query in Queries:
    if Query[0] == '1':
      is_reversed = not is_reversed
    else:
      if (Query[1] == '1') ^ is_reversed:
        prefix = Query[2] + prefix
      else:
        suffix += Query[2]
  ans = prefix + S + suffix
  if not is_reversed:
    print(ans)
  else:
    print(''.join(list(reversed(ans))))

main()
s=str(input())
q=int(input())
now = 0
mae,usiro="",""
for _ in range(q):
  lis = list(map(str,input().split()))
  if int(lis[0]) == 1:
    now = (now+1)%2
  else:
    if (int(lis[1])+now)%2 == 1:
      mae = lis[2]+mae
    else:
      usiro= usiro +lis[2]
s = mae+s+usiro
if now ==0:
  print(s)
else:
  print(s[::-1])
s=input()
n=int(input())
a,b=[],[]
p=0
for i in range(n):
    l=input().split()
    if len(l)==1:
        p+=1
    else:
        k=int(l[1])
        if k%2==p%2:
            b+=[l[2]]
        else:
            a+=[l[2]]
if p%2==1:
    s=s[::-1]
    a,b=b,a
print(("".join(a)[::-1])+s+"".join(b))
from collections import deque
s=deque(input())
q=int(input())
direction=1
for i in range(q):
  k=deque(input().split())
  if k[0]=='1':
    direction*=(-1)
  if k[0]=='2':
    if k[1]=='1':
      if direction==1:
        s.appendleft(k[2])
      else:
        s.append(k[2])
    if k[1]=='2':
      if direction==1:
        s.append(k[2])
      else:
        s.appendleft(k[2])
if direction==-1:
  s.reverse()
print("".join(list(s)))
S = str(input())
Q = int(input())

head = ""
tail = ""
main = S

status = 0

while Q:
  Q -= 1
  l = list(map(str,input().split()))
  if l[0] == "1":
    status = (status+1)%2
  else:
    letter = l[2]
    if l[1] == "1":
      if status == 0:
        head += letter
      else:
        tail += letter
    else:
      if status == 0:
        tail += letter
      else:
        head += letter

if status == 0:
  print(head[::-1]+main+tail)
else:
  print(tail[::-1]+main[::-1]+head)
import sys
def input():
	return sys.stdin.readline()[:-1]

s = input()
#n = len(s)
q = int(input())
front = ""
back = ""
sgn = 0
for _ in range(q):
	query = input().split()
	if query[0] == "1":
		sgn ^= 1
	else:
		f, c = int(query[1])-1, query[2]
		if f ^ sgn == 0:
			front += c
		else:
			back += c
if not sgn:
	print(front[::-1] + s + back)
else:
	print(back[::-1] + s[::-1] + front)
# D - String Formation
from collections import deque
s = deque(input())
q = int(input())
odd = 0
for i in range(q):
    t,*fc = input().split()
    if t=='1': odd ^= 1 #t1
    else: #t2
        if odd ^ (int(fc[0])-1): s.append(fc[1])
        else: s.appendleft(fc[1])
if odd: deque.reverse(s)
print(''.join(s))
# D - String Formation
s = input()
q = int(input())

f = ''
b = ''
odd = 0
for i in range(q):
    t,*fc = input().split()
    if t=='1': odd ^= 1 #t1
    else: #t2
        if odd ^ (int(fc[0])-1): b += fc[1]
        else: f += fc[1]

if odd: print(b[::-1] + s[::-1] + f)
else: print(f[::-1] + s + b)
S=input()
Q=int(input())
reverse=0
back=""
front=""
for i in range(Q):
    T=input()
    if T[0]=="1":
        reverse=1-reverse
    else:
        q,F,C=T.split()
        F=int(F)
        if F-reverse==1:
            front=C+front
        else:
            back+=C

S=front+S+back
if reverse==0:
    print(S)
else:
    S=S[::-1]
    print(S)
import collections
S = list(input())
s = collections.deque(S)
Q = int(input())
mode = 1
for _ in range(Q):
    tmp = tuple(input().split())
    if len(tmp) == 1:
        mode = 1 ^ mode
    else:
        t, f, c = tmp
        f = int(f)
        f -= 1
        if mode ^ f:
            s.appendleft(c)
        else:
            s.append(c)
if mode:
    print("".join(list(s)))
else:
    print("".join(list(s)[::-1]))
from collections import deque
s = deque(input())
n = int(input())
f = 0
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    if (l[1] == "1" and f == 0) or (l[1] == "2" and f == 1):
      s.appendleft(l[2])
    else:
      s.append(l[2])
  else:
    if f == 0:
      f = 1
    else:
      f = 0
if f == 1:
  s.reverse()
print("".join(s))
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')