peterverebics/CodeNet_Python_118 huggingface dataset:
from collections import deque

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

AppendLeft = ""
AppendRight = ""
for i in range(Q):
    QList = list(input().split())
    
    if QList[0] == '1':
        S.appendleft(AppendLeft)
        S.append(AppendRight)
        S.reverse()
        AppendLeft = ""
        AppendRight = ""
    else:
        if QList[1] == '1':
            AppendLeft += QList[2]
        else:
            AppendRight += QList[2]
print("".join(list(S)))
from collections import deque

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

cur = 1
d = deque([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:
            d.append(c)
        else:
            d.appendleft(c)

if cur == 1:
    ans = "".join(d)
else:
    d.reverse()
    ans = "".join(d)

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

S = input()
Q = int(input())
A = [(input().split()) for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = S + A[i][2]
    else:
      S = A[i][2] + S
      
print(S)
s = list(str(input()))
q = int(input())
for i in range (q):
    t = list(str(input()))
    if t[0] == '1':
        s.reverse()
    elif t[0] == '2':
        if t[2] == '1':
            s.append(t[4])
        elif t[2] == '2':
            s.reverse()
            s.append(t[4])
            s.reverse()
s.reverse()
print(''.join(s))
s = input()
q = int(input())
inv = 1
for i in range(q):
  t = input()
  if t[0] == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if f =='1' and inv == 1:
      s = c+s
    else:
      s = s+c

print(s[::inv])
S = input()
L = list(S)
Q = int(input())

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if not len(L) == 1:
            L.reverse()
    else:	
        if a[1] == '1':
            L.append(a[2])
        else:
            L.insert(0, a[2])
L.reverse()
A = "".join(L)
print(A)
s = input()
q = int(input())
a = [s]

for i in range(q):
    so = input()
    if so == '1':
        a[0], a[-1] = a[-1], a[0]
    else:
        d, f, c = so.split()
        if f == '1':
            a.insert(0, c)
        else:
            a.insert(-1, c)


print(''.join(a))
from collections import deque
s = input()
d = deque()
d.append(s)
n = int(input())
count = 0
for i in range(n):
    j = list(input().split())
    if j[0] == '1':
        count+=1
    else:
        if (count + int(j[1])) % 2 == 1:
            d.appendleft(j[2])
        else:
            d.append(j[2])
ans = ""
if count % 2 == 1:
    while d:
        ans += d.pop()
else:
    while d:
        ans += d.popleft()
print(ans)
# input1 = list(map(int, (input().split())))

S = input()
N = int(input())
c = False
for i in range(N):
    Q = list(input().split())
    a = int(Q[0])
    if a == 1:
        c = not c
    elif a == 2:
        if c == True:
            S = S[::-1]
        b = int(Q[1])
        if b == 1:
            S = Q[2] + S
        elif b == 2:
            S = S + Q[2]
if c == True:
    S = S[::-1]
print(S)
s=input()
q=int(input())
trans=0
aft=""
bef=""
for i in range(q):
  que=input()
  if que[0]=="1":
    trans=1-trans
  else:
    que=que.split()
    if (que[1]=="1" and trans==0) or (que[1]=="2" and trans==1):
      bef=bef+que[2]
    else:
      aft=aft+que[2]
if trans==0:
  print("".join(bef[::-1])+s+"".join(aft))
else:
  print("".join(aft[::-1])+s+"".join(bef))
from collections import deque
d=deque(map(str,input().split()))
q=int(input())
for _ in range(q):
    ss=input().split()
    if ss[0]==str(1):
        d.reverse()
    else:
        if ss[1]==str(1):
            d.appendleft(ss[2])
        else:
            d.append(ss[2])
for j in d:
    print(j,end='')
s = input()
q = int(input())
status = 1
for i in range(q):
    query = [i for i in input().split()]
    if query[0] == "1":
        status *= -1
    else:
        if (query[1] == "1" and status == 1) or (query[1] == "2" and status == -1):
            s = query[2] + s
        else:
            s = s + query[2]

print(s if status else reversed(s))
from collections import deque

s = input()

r = False
d = deque()
d.append(s)

q = int(input())
for i in range(q):
    t = input()
    if t == "1":
        r = not r
    else:
        t, f, c = list(t.split())
        f = False if f=="1" else True

        if r == f:
            d.appendleft(c)
        else:
            d.append(c)

if r:
    d.reverse()

print("".join(d))
S = input()
Q = [input().strip() for i in range(int(input()))]

r_flg = False
for query in Q:
  if query == "1":
    r_flg = not r_flg
  else:
    _, f, c = query.split()
    f_flg = (f == "1")
    end = (r_flg ^ f_flg)
    if end:
      S = S + c
    else:
      S = c + S

if not r_flg:
  S = S[::-1]
  
print(S)
S=input()
Q=int(input())
A= [input().split() for i in range(Q)]

from collections import deque
ans = deque()
tmp=0
ans.append(S)

for li in A:
    if li[0]=='1':
        tmp=(tmp+1)%2
    else:
        if (tmp+int(li[1]))%2 == 1:
            ans.appendleft(li[2])
        else:
            ans.append(li[2])
if tmp == 0:
    re=map(str, list(ans))
    print(''.join(re))
else:
    re=map(str, list(ans)[::-1])
    print(''.join(re))
import math
S=input()
Q=int(input())
Rev=1
front=""
back=""
for i in range(Q):
    a=input().split()
    if a[0]=="1":
        Rev=Rev*-1
        continue
    if (a[1]=="1"and Rev==1) or (a[1]=="2" and Rev==-1):
        front+=a[2]
    else:
        back+=a[2]
print(front)
if Rev==1:
    #str(front.reverse().extend(S).extend(back))
    print(front[::-1]+S+back)
    #str(front.reverse()+S+back)
else:
    print(back[::-1]+S[::-1]+front)
s=input()
q=int(input())
count=0
while(q):
    q-=1
    t=list(input().split())
    if t[0]=='2':
        f=t[1]
        c=t[2]
        if f=='1':
            s=c+s
        else:
            s=s+c
    else:
        count+=1
if count%2==1:
    s=s[::-1]
print(s)
S = input()
Q = int(input())

rev = 0
for _ in range(Q):
  TFC = input()
  if len(TFC) == 1: # T == 1
    rev ^= 1
  else:
    T, F, C = (i for i in TFC.split())  
    if F == '1' and rev:
      S = S + C
    else:
      S = C + S

if rev:
  print(S[::-1])
else:
  print(S)
import sys
import math
import itertools
from collections import deque

s=input()
Q=deque([])
for c in s:
    Q.append(c)
q=int(input())
rev=1
for _ in range(q):
    opt=list(input().split())
    if(opt[0]=="1"):
        rev^=1
    else:
        f=int(opt[1])
        if(rev==1):
            f=3-f
        if(f==1):
            Q.appendleft(opt[2])
        else:
            Q.append(opt[2])
if(rev==1):
    Q.reverse()
for ch in Q:
    print(ch,end="")
import sys
input = lambda: sys.stdin.readline().rstrip()
s=[i for i in input()]
x=0 ; st=[[],[]]
for _ in range(int(input())):
    inp=list(map(str,input().split()))
    if len(inp)==1: x^=1
    else: st[(int(inp[1])-1)^x].append(inp[2])
if x==0:
    st[0].reverse()
    ans=st[0]+s+st[1]
elif x==1:
    st[1].reverse()
    ans=st[1]+s+st[0]
print(''.join(ans))
S = input() 
Q = int(input())
for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        pass
    else:
        S = S + lists[2]
print(S)
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=[[],[]]
    
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])
print("".join(ans[0])+s+"".join(ans[1]))
from sys import stdin
input = stdin.readline
S = input()
Q = int(input())
s = [S[0]]
A = []
count = 0
for i in range(Q):
  A += [input().split()]
for i in range(Q):
  if int(A[i][0]) == 2:
    if count % 2 == 1:
      s = s[::-1]
    count = 0
    if int(A[i][1]) == 1:
      s = [A[i][2]] + s
    else:
      s = s + [A[i][2]]
  else:
    count += 1
    if i == Q-1:
      if count % 2 == 1:
        s = s[::-1]
 
 
result = ''.join(s)
print(result)
from collections import deque
s = deque(input())
q = int(input())

flag = 1
for i in range(q):
  st = input().split()
  if int(st[0]) == 1:
    flag *= -1
  else:
    tmp = int(st[1])*flag
    if tmp == 1 or -2:
      s.appendleft(st[2])
    else:
      s.append(st[2])

if flag == -1:
  s.reverse()
print(''.join(s))
S = input()
Q = int(input())
que2 = []
que2.append(S)
rv_flag= 0
for _ in range(Q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        rv_flag = rv_flag + 1
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.append(que[2])
if rv_flag % 2 == 1:
    que2.reverse()
ans = "".join(que2)
print(ans)
S=input()
Q=int(input())
rev=1
for i in range(Q):
    t=input()
    if t=='1':
        rev+=1
        rev=rev%2
    else:
        _,F,C=t.split(" ")
        if (int(F)+rev)%2==1:
            S=C+S
        else:
            S=S+C

if rev==1:
    print(S[::-1])
else:
    print(S)
S = input()
Q = int(input())
for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0]=='1':
        ''.join(reversed(list(S)))
    else:
        if query[1]=='1':
            S = query[2] + S
        else:
            S = S + query[2]

print(S)
S = str(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
A_S = ''
S_A = ''
for i in range(Q):
    if querry[i][0] == '1':
        S = S[::-1]
        A_S = A_S[::-1]
        S_A = S_A[::-1]
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            A_S += querry[i][2] 
        elif querry[i][1] == '2':
            S_A += querry[i][2]

print(A_S + S + S_A)
import sys
input = sys.stdin.readline
S = list(input())
n = int(input())
s = []
for i in range(n):
    array = list(map(str,input().split()))
    s.append(array)
for i in range(n):
    if s[i][0] == "1":
        S.reverse()
    else:
        if s[i][1] == "1":
            S.insert(0,s[i][2])
        else:
            S.append(s[i][2])

print("".join(S))
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:
    print(t[::-1] + s + h)
item = []
item.append(input())
n = int(input())
for i in range(n):
    tmp = input()
    if tmp[0] == '1':
        item.reverse()
    else:
        _, q, s = tmp.split()
        if q == '1':
            item = [s] + item
        else:
            item += [s]
print(''.join(item))
from collections import deque
S = deque([i for i in input()])
Q = int(input())
#list = [['1', "0", "0"] for i in range(Q) ]
for i in range(Q):
    a = input()
    if a[0] == '2':
        p, q, r = map(str, a.split())
        if q == "1":
            S.appendleft(r)
        else:
            S.append(r)
    else:
        tmp = S[0]
        S[0] = S[-1]
        S[-1] = tmp
ans = ""
N = len(S)
for i in range(N):
    ans = ans + S.popleft()
print(ans)
import sys
input = sys.stdin.readline


def main():

    s = input()
    q = int(input())
    ls = [input().split() for _ in range(q)]

    for t in ls:
        if t[0] == '1':
            s = s[::-1]
        elif t[0] == '2':
            if t[1] == '1':
                s = t[2] + s
            elif t[1] == '2':
                s = s + t[2]
    
    print(s[:-1])

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

left = []
right = []

for _ in range(q):
    Q = list(input().split())
    if int(Q[0]) == 1:
        left, right = right[::-1], left[::-1]

    else:
        if int(Q[1]) == 1:
            left = [Q[2]] + left
        else:
            right.append(Q[2])

print(''.join(left) + s + ''.join(right))
syoki_str = input()
syori_cnt = int(input())

result = ""
for i in range(syori_cnt):
    line = input().split(" ")
    if line[0] == "1":
        result = ''.join(list(reversed(syoki_str)))
    else:
        output = []
        if line[1] == "1":
            output.append(line[2])
            output.append(syoki_str)
        else:
            output.append(syoki_str)
            output.append(line[2])
        result = ''.join(output)

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

for i in range(q):
    query = input()
    try:
        int(query)
        t = query
    except:
        t, f, c = query.split()

    if t == "1":
        s = s[-1] + s[1:-1] + s[0]
    else:
        if f == "1":
            s = c + s
        else:
            s = s + c

print(s)
from collections import deque

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

que = deque()

for s in S:
    que.append(s)

for _ in range(Q):
    query = input().split()

    if query[0] == "1":
        r = que.pop()
        l = que.popleft()
        que.append(l)
        que.appendleft(r)
    else:
        if query[1] == "1":
            que.appendleft(query[2])
        else:
            que.append(query[2])


print("".join(list(que)))
from collections import deque

deq=deque()
deq.append(input())
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%2!=0:
			deq.appendleft(a[4])
		else:
			deq.append(a[4])
	else:
		if x%2!=0:
			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())
for i in range(q):
  aa=list(map(str,input().split()))
  if len(aa)==1:
    s.reverse()
  else:
    if aa[1]=="1":
      s.insert(0,aa[2])
    else:
      s.append(aa[2])
print(*s,sep='')
S = input()
Q = int(input())
Qu= [list(input().split()) for _ in range(Q)]

r = 0

B = []
A = []

for i in range(Q):
  if int(Qu[i][0]) == 1:
    r = 1 - r
  else:
    F = int(Qu[i][1])
    C = Qu[i][2]
    F -= 1
    if F == r:
      B.append(C)
    else:
      A.append(C)

if r == 0:
  B.reverse()
  print("".join(B + [S] + A))
else:
  A.reverse()
  print("".join(A + [S] + B))
s = [input()]
q = int(input())
for _ in range(q):
    i = input().split()
    if int(i[0]) == 1:
        s = s[::-1]
    elif int(i[0]) == 2:
        if int(i[1]) == 1:
            s.insert(0, i[2])
        elif int(i[1]) == 2:
            s.append(i[2])

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

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

reverseFlag = 1

for _ in range(q):
    query = input().strip()
    if query[0] == "1":
        reverseFlag = 1 - reverseFlag
    else:
        lf = reverseFlag + int(query[2])
        if lf % 2 == 0:
            s.append(query[4])
        else:
            s.appendleft(query[4])

if reverseFlag == 1:
    s.reverse()
print("".join(s))
S = input()
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 = b[1] + S
    else:
      S += b[1]
print (S if f % 2 == 1 else S[::-1])
S = input()
Q = int(input())
#inp = [input().split() for _ in range(Q)]

# 無駄なところ除く

cnt = 0
for i in range(Q):
    inp = input().split()
    if len(inp) == 1:
        cnt += 1
        #S = S[::-1]
    else:
        if cnt % 2 != 0:
            S = S[::-1]
            cnt = 0
        f, c = inp[1:]
        if int(f) == 1:
            S = c + S
        else:
            S = S + c
print(S)
from collections import deque

s = input()
q = int(input())
r = 1
top = deque()
top.append(s)
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:
            top.append(c)
        else:
            top.appendleft(c)
ans = "".join(top)
ans = ans if r == 1 else s[::-1]
print(ans)
from collections import deque


d = deque()
S = input()
d.append(S)
q = int(input())

for i in range(q):
    query = input()
    if query == '1':
        if len(d) > 1:
            d.reverse()
    else:
        s_lis = query.split()
        n = int(s_lis[0])
        f = int(s_lis[1])
        c = s_lis[2]
        if f == 1:
            d.appendleft(c)
        else:
            d.append(c)

d_lis = list(d)

print("".join(d_lis))
s = input()
q_number = int(input())
reverse_flag = 1
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    if int(temp[1])*reverse_flag == 1 or -2:
      s = temp[2] + s
    else:
      s = s + temp[2]      
      
if reverse_flag == -1:
  s = s[::-1]
print(s)
s = input()
Q = int(input())
for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        s = s[-1] + s[1:-1] + s[0]
    else:
        if q[1] == "1":
            s = q[2] + s 
        else:
            s = s + q[2]
print(s)
from collections import deque
S=deque(input())
q=int(input())
for i in range(q):
  c=list(input().split())
  print(c)
  if c[0]=='1':
    S.reverse()
  elif c[0]=='2':
    if c[1]=='1':
      S.appendleft(c[2])
    elif c[1]=='2':
      S.append(c[2])
ans=''.join(S)
print(ans)
import collections
dq = collections.deque()
s = input()
dq.append(s)
is_reveresed = False
q = int(input())
for i in range(q):
    query = input()
    if query[0] == '1':
        is_reveresed = not is_reveresed
    else:
        f = query[2]
        c = query[4]
        if (f == '1') ^ is_reveresed:
            dq.appendleft(c)
        else:
            dq.append(c)
if is_reveresed:
    dq.reverse()
print(''.join(dq))
s = input()
q = int(input())
a = ""
b = ""
for i in range(q):
  l = list(input().split())
  if len(l) == 1:
    a, b = b, a
  else:
    if l[1] == "1":
      s = a + s
      a = l[2]
      if b == "":
        b = s
        s = ""
    else:
      s = s + b
      b = l[2]
      if a == "":
        a = s
        s = ""
print(a+s+b)
from collections import deque


s = input()
q = int(input())
op = [input().split() for _ in range(q)]

ans = deque()
ans.append(s)

for i in op:
    if i[0] == "1":
        ans.reverse()
    if i[0] == "2":
        if i[1] == "1":
            ans.appendleft(i[2])
        elif i[1] == "2":
            ans.append(i[2])

print("".join(ans))
s = input()
q = int(input())
for i in range(q):
    t = input().split(' ')
    if t[0] == '1':
        s = s[-1] + s[1:-1] + s[0] if len(s) > 1 else s
    else:
        if t[1] == '1':
            s = t[2] + s
        else:
            s = s + t[2]
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==False and f=="1") or (rev==True and f=="2"):
         S.appendleft(c)
      else:
         S.append(c)
if rev==False:
   print("".join(S))
else:
   print("".join(reversed(S)))
s = input()
sc = s[::-1]
n = int(input())
l = [list(input().split()) for i in range(n)]

last = 1

for i in range(n):
    if l[i][0] == '1':
        last = last * -1
    else:
        s = l[i][2] + s
        sc += l[i][2]

if last > 0:
    print(s)
else:
    print(sc)
s = []
s.append(input())
Q = int(input())
cnt = 0
for _ in range(Q):
    tmp = input().split()
    if tmp[0] == '1':
        cnt += 1
        continue
    else:
        if cnt % 2:
            pass
        else:
            s.reverse()
        if tmp[2] == 1:
            s.insert(0, tmp[2])
        else:
            s.append(tmp[2])
if cnt % 2:
    pass
else:
    s.reverse()
print(''.join(s))
s = input()
q = int(input())
flag = 1
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        flag *= -1
    else:
        if flag * int(A[1]) == 1 or -2:
            s = A[2]+s
        else:
            s = A[2]+s
if flag == -1:
    print(s[::-1])
else:
    print(s)
from collections import deque

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

for i in range(Q):
    QList = deque(input().split())
    
    if QList[0] == '1':
        S.reverse()
    else:
        if QList[1] == '1':
            S.appendleft(QList[2])
        else:
            S.append(QList[2])
print("".join(list(S)))
S = input()
Q=int(input())
Query=[S]
flag = True
for i in range(Q):
  x=input().split()
  if len(x)==1:
    flag = not flag
  else:
    if flag:
      if x[1]=="1":
        Query=[x[2]]+Query
      else:
        Query.append(x[2])
    else:
      if x[1]=="1":
        Query.append(x[2])
      else:
        Query=[x[2]]+Query
if flag==False:
  Query.reverse()

print("".join(Query))
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn and int(qq[1])-2:
            l+=qq[2]
        else:
            s.append(qq[2])

text=l+"".join(s)
print(text if turn else text[::-1])
from collections import deque

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

deque = deque([S])
for _ in range(Q):
  pack = input().split()

  T = int(pack[0])
  if T == 1:
    deque[0], deque[-1] = deque[-1], deque[0]

  if T == 2:
    F, C = int(pack[1]), pack[2]
    if F == 1:
      # 最初に追加するパターン
      deque.appendleft(C)
    if F == 2:
      # 最後尾に追加するパターン
      deque.append(C)

print("".join(deque))
inital_string = input()
num_of_q = int(input())
flag = True

for i in range(num_of_q):
  q = input()
  if q[0] == '1':
    flag = not flag
  else:
    if q[2] == "1":
      if flag:
        inital_string = inital_string + q[4]
      else:
      	inital_string = q[4] + inital_string
    else:
      if flag:
        inital_string = q[4] + inital_string
      else:
      	inital_string = inital_string + q[4]
if flag:
  inital_string = inital_string[::-1]
print(inital_string)
from collections import deque
d = deque()
s = input()
d.append(s)
q = int(input())
for i in range(q):
    tfc = input().split()
    if int(tfc[0]) == 1:
        d.reverse()
#         print('reverse:', d)
    else:
        if int(tfc[1]) == 1:
            d.appendleft(tfc[2])
#             print('appendleft:', d)
        else:
            d.append(tfc[2])
#             print('append:', d)
print(''.join(d))
S=input()
Q=int(input())
F=0
C=''
while Q>=1:
  tfc=list(input().split())
  if int(tfc[0])==1:
    box1=S[0]
    box2=S[-1]
    S=box2+S[1:-1]+box1
  elif int(tfc[0])==2:
    if int(tfc[1])==1:
      S=tfc[2]+S
    elif int(tfc[1])==2:
      S=S+tfc[2]
  Q-=1
ans=''.join(S)
print(ans)
from collections import deque
S = deque([input(), ])
q = int(input())
r = False
for _ in range(q):
    t = input().split()
    if len(t) == 1:
        r = not r
    else:
        t[1] = int(t[1]) - 1
        if (not t[1] and not r) or (t[1] and r):
            S.appendleft(t[2])
        else:
            S.append(t[2])
if r:
    S = list(S)
    print(''.join(S[::-1]))
else:
    print(''.join(S))
from collections import deque

s = 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)
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.insert(0,ans[-1])
    ans.append(ans[1])
    ans.pop(1)
    ans.pop(-2)

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

print(''.join(ans))
from collections import deque

S = deque(input().strip())
q = int(input())

rev = True
for _ in enumerate(range(q)):
    query = input().split()
    if query[0] == '1':
        rev = not rev
    else:
        if (query[1] == '1') ^ rev:
            S.appendleft(query[2])
        else:
            S.append(query[2])
S = S if not rev else reversed(S)
print(*S, sep='')
from collections import deque
d=deque()
s=input()
d.append(s)
Q=int(input())
for i in range(Q):
    r=input()
    if len(r.split()) == 3:
        T,F,C=r.split()
    else:
        T='1'
    if T == '1':
        s=d.pop()
        d.rotate(1)
        d.append(s)
        continue
    if T == '2':
        if F == '1':
            d.appendleft(C)
        if F == '2':
            d.append(C)

print("".join(d))
A = input()
B = int(input())
C = ""
for i in range(B):
    D = input().split()
    if D[0] == "1":
        A,C = C,A
    else:
        if D[1] == "1":
            A += D[2]
        else:
            C += D[2]
A = A[::-1]
print(A+C)