CodeEff/ECCO huggingface dataset:
# Original solution
import sys
import collections
import itertools


def resolve(in_):
    one = ord(b'1')
    two = ord(b'2')
    # print(f'{one=} {two=}')

    S = in_.readline().strip()
    q = collections.deque(S)
    # print(f'{S=} {q=}')

    reverse_flag = 0
    Q = int(in_.readline())
    for query in itertools.islice(in_, Q):
        T = query[0]
        if T == one:
            reverse_flag ^= 1 
            # q.reverse()
        elif T == two:
            if reverse_flag:
                q.reverse()
                reverse_flag = 0
            F = query[2]
            C = query[4]
            if F == one:
                q.appendleft(C)
            elif F == two:
                q.append(C)
    else:
        if reverse_flag:
            q.reverse()
            reverse_flag = 0

    return bytes(q)


def main():
    answer = resolve(sys.stdin.buffer)
    print((answer.decode('ascii')))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import collections
import itertools


def resolve(in_):
    one = ord(b'1')
    two = ord(b'2')
    # print(f'{one=} {two=}')

    S = in_.readline().strip()
    q = collections.deque(S)
    # print(f'{S=} {q=}')

    reverse_flag = False
    Q = int(in_.readline())
    for query in itertools.islice(in_, Q):
        T = query[0]
        if T == one:
            reverse_flag ^= True 
            # q.reverse()
        elif T == two:
            F = query[2]
            C = query[4]
            if (F == one) ^ reverse_flag:
                q.appendleft(C)
            else:
                q.append(C)
    else:
        if reverse_flag:
            q.reverse()
            reverse_flag = 0

    return bytes(q)


def main():
    answer = resolve(sys.stdin.buffer)
    print((answer.decode('ascii')))


if __name__ == '__main__':
    main()
# Original solution
S = input()
Q = int(input())
reverse = False
for _ in range(Q):
    cmd = input().split()
    if cmd[0] == "1":
        reverse = not reverse
    else:
        top = (cmd[1] == "1") ^ reverse
        S = cmd[2] + S if top else S + cmd[2]
print(S[::-1]) if reverse else print(S)


# Optimized solution
S = input()
Q = int(input())
head, tail = "", ""
reverse = False
for _ in range(Q):
    cmd = input().split()
    if cmd[0] == "1":
        reverse = not reverse
    else:
        top = (cmd[1] == "1") ^ reverse
        if top:
            head += cmd[2]
        else:
            tail += cmd[2]
print(tail[::-1] + S[::-1] + head) if reverse else print(head[::-1] + S + tail)
# Original solution
from collections import deque

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

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
    else:
        if(revFlag):
            s.reverse()
            revFlag = False
        
        if(b == '1'):
            s.appendleft(c)
        else:
            s.append(c)

if(revFlag):
    s.reverse()
    
print(*s, sep='')


# Optimized solution
from collections import deque

revFlag = False

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

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')
# Original solution
from sys import stdin
s = list(stdin.readline().rstrip())
q = int(stdin.readline().rstrip())
t = []
for i in range(q):
    t.append([x for x in stdin.readline().rstrip().split()])
r = 0
for i in range(q):
    if int(t[i][0]) == 1:
        if r == 1:
            r = 0
        else:
            r = 1
    else:
        if (int(t[i][1]) + r) % 2 == 0:
            s.append(t[i][2])
        else:
            s.insert(0,t[i][2])
if r == 1:
    s = list(reversed(s))
s = ''.join(s)
print(s)

# Optimized solution
from sys import stdin
s = list(stdin.readline().rstrip())
q = int(stdin.readline().rstrip())
t = []
k = []
for i in range(q):
    t.append([x for x in stdin.readline().rstrip().split()])
r = 0
for i in range(q):
    if int(t[i][0]) == 1:
        if r == 1:
            r = 0
        else:
            r = 1
    else:
        if (int(t[i][1]) + r) % 2 == 0:
            s.append(t[i][2])
        else:
            k.append(t[i][2])
k = list(reversed(k))
k.extend(s)
if r == 1:
    k = list(reversed(k))
k = ''.join(k)
print(k)
# Original solution
from collections import deque


def main():
    s = input()
    q = int(input())
    d = deque(s)
    is_reversed = False

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

        if query[0] == "1":
            if is_reversed:
                is_reversed = False
            else:
                is_reversed = True

        elif query[0] == "2":
            if query[1] == "1":
                if is_reversed:
                    d.append(query[2])
                else:
                    d.appendleft(query[2])
            elif query[1] == "2":
                if is_reversed:
                    d.appendleft(query[2])
                else:
                    d.append(query[2])

    if is_reversed:
        print(*(list(d)[::-1]), sep="")
    else:
        print(*list(d), sep="")


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    s = list(input())
    t = []
    q = int(input())

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

        if query[0] == "1":
            s, t = t, s
        elif query[0] == "2":
            if query[1] == "1":
                t.append(query[2])
            elif query[1] == "2":
                s.append(query[2])

    print(*(t[::-1] + s), sep="")


if __name__ == "__main__":
    main()
# Original solution
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
def main():
    S_ = S()
    S_que = deque(S_)
    Q = I()

    for i in range(Q):
        q = LS()
        if int(q[0]) == 1:
            S_que.reverse()
        elif int(q[0]) == 2:
            if int(q[1]) == 1:
                S_que.appendleft(q[2])
            else:
                S_que.append(q[2])
    print((''.join(map(str, S_que))))

if __name__ == "__main__":
    main()


# Optimized solution
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
def main():
    S_ = S()
    S_que = deque(S_)
    Q = I()
    cnt = 0
    for i in range(Q):
        q = LS()
        if int(q[0]) == 1:
            cnt += 1
        elif int(q[0]) == 2:
            if int(q[1]) == 1:
                if cnt % 2 == 0:
                    S_que.appendleft(q[2])
                else:
                    S_que.append(q[2])
            else:
                if cnt % 2 == 1:
                    S_que.appendleft(q[2])
                else:
                    S_que.append(q[2])
    if cnt % 2 == 1:
        S_que.reverse()
    print((''.join(map(str, S_que))))

if __name__ == "__main__":
    main()
# Original solution
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def main():
    import sys
    input = sys.stdin.readline
    s = input().rstrip("\n")
    q = int(eval(input()))
    han = 0
    qq=[input().split() for i in range(q)]

    for que in qq:
        if len(s) == 1 and que[0] == "1":
            continue

        if que[0] == "1":
            han += 1
            #print(han, s, que)
        else:
            if han % 2 == 0:  # 反転なし
                if que[1] == "1":
                    s = que[2]+s
                else:
                    s += que[2]
            else:  # あり
                if que[1] == "1":
                    s +=que[2]
                else:
                    s = que[2]+s
            #print(han, s, que)

    if han % 2 == 0:
        print(s)
    else:
        print((s[::-1]))


if __name__ == '__main__':
    main()


# Optimized solution
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def main():
    import sys
    input = sys.stdin.readline
    s = input().rstrip("\n")
    q = int(eval(input()))
    
    qq = [input().split() for i in range(q)]
    cnt=0
    r=""
    l=""
    #print(qq)
    for que in qq:
        if que[0] == "1":
            #print("a")
            r,l=l,r
            cnt+=1
            #print(r,l,cnt)
        else:
            if que[1] == "1":
                l+=que[2]
            else:
                r+=que[2]
            #print(r,l, que)
    #print(r,l)
    if cnt%2==0:
        print((l[::-1]+s+r))
    else:
        print((l[::-1]+s[::-1]+r))



if __name__ == '__main__':
    main()
# Original solution
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline
S = S()
S = [S[i] for i in range(len(S))]
Q = I()
rev = False
for i in range(Q):
    q = LS()
    if q[0] == '1':
        rev = not rev
        continue
    if (q[1] == '1') ^ rev:
        S = [q[2]]+S
    else:
        S = S+[q[2]]
if rev:
    ans = ''.join(S[::-1])
else:
    ans = ''.join(S)

print(ans)




# Optimized solution
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline
S = S()
S = [S[i] for i in range(len(S))]
QS= deque(S)
S = QS
Q = I()
rev = False
for i in range(Q):
    q = LS()
    if q[0] == '1':
        rev = not rev
        continue
    if (q[1] == '1') ^ rev:
        S.appendleft(q[2])
    else:
        S.append(q[2])
if rev:
    ans = ''.join(reversed(S))
else:
    ans = ''.join(S)

print(ans)
# Original solution
from sys import stdin
S = (stdin.readline().rstrip())
Q = int(stdin.readline().rstrip())
cnt = 0
ccnt = 0
s = ["@"]
for i in range(Q):
    data = [(x) for x in stdin.readline().rstrip().split()]
    if data[0] == "2":
        ccnt = 0
        if data[1] == "1":
            if cnt % 2 == 0:
                #s = "".join([data[2],s])
                s.insert(0,data[2])
            else:
                #s = "".join([s,data[2]])
                s.append(data[2])
        else:
            if cnt % 2 == 0:
                #s = "".join([s,data[2]])
                s.append(data[2])
            else:
                #s = "".join([data[2],s])
                s.insert(0,data[2])
    else:
        cnt += 1
s = "".join(s)
if cnt % 2 != 0:
    s = s[::-1]
if cnt % 2 != 0:
    S = S[::-1]
ans = s.replace("@",S)
print(ans)

# Optimized solution
from sys import stdin
S = (stdin.readline().rstrip())
Q = int(stdin.readline().rstrip())
cnt = 0
ccnt = 0
s = "@"
for i in range(Q):
    data = [(x) for x in stdin.readline().rstrip().split()]
    if data[0] == "2":
        ccnt = data[2]
        if data[1] == "1":
            if cnt % 2 == 0:
                s = "".join([ccnt,s])
            else:
                s = "".join([s,ccnt])  
        else:
            if cnt % 2 == 0:
                s = "".join([s,ccnt])
            else:
                s = "".join([ccnt,s])
    else:
        cnt += 1
if cnt % 2 != 0:
    s = s[::-1]
if cnt % 2 != 0:
    S = S[::-1]
ans = s.replace("@",S)
print(ans)
# Original solution
from sys import stdin
s = str(stdin.readline().rstrip())
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに
q= int(stdin.readline().rstrip())
hanten = 0
for i in range(q):
    l = list(map(str, stdin.readline().rstrip().split()))
    if int(l[0]) == 1:
        hanten += 1
    else:
        if int(l[1])==1:
            if hanten%2 == 0:
                s = l[2]+s
            else:
                s = s+l[2]
        else:
            if hanten%2==0:
                s = s+l[2]
            else:
                s = l[2]+s

if hanten%2==0:
    print(s)
else:
    print((s[::-1]))


# Optimized solution
from sys import stdin
s = str(stdin.readline().rstrip())
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに
q= int(stdin.readline().rstrip())
hanten = 0
t=""
u=""

for i in range(q):
    l = list(map(str, stdin.readline().rstrip().split()))
    if int(l[0]) == 1:
        t,u = u,t
        hanten ^= 1
    else:
        if int(l[1])==1:
            t+=l[2]
        else:
            u+=l[2]


if hanten==0:
    print((t[::-1]+s+u))
else:
    print((t[::-1]+s[::-1]+u))
# Original solution
S = input()
N = int(input())
direct = 0
for i in range(N):
  X = input().split()
  if len(X) == 1:
    direct = 1 - direct
  else:
    if (X[1] == "1" and direct == 0) or (X[1] == "2" and direct == 1):
      S = X[2] + S
    else:
      S += X[2]
print(S) if direct == 0 else print(S[::-1])


# Optimized solution
S = input()
f = ""
N = int(input())
direct = 0
for i in range(N):
  X = input().split()
  if len(X) == 1:
    direct = 1 - direct
  else:
    if (X[1] == "1" and direct == 0) or (X[1] == "2" and direct == 1):
      f += X[2]
    else:
      S += X[2]
print(f[::-1]+S) if direct == 0 else print(S[::-1]+f)
# Original solution
from collections import deque
d = deque()
S = input()
d.append(S)
N = int(input())
direct = 0
for i in range(N):
  X = input().split()
  if len(X) == 1:
    direct = 1 - direct
  else:
    if (X[1] == "1" and direct == 0) or (X[1] == "2" and direct == 1):
      d.appendleft(X[2])
    else:
      d.append(X[2])
      
S = "".join(list(d))
print(S) if direct == 0 else print(S[::-1])


# Optimized solution
from collections import deque
d = deque()
S = input()
d.append(S)
N = int(input())
direct = 1
for i in range(N):
  X = input().split()
  if len(X) == 1:
    direct *= -1
  else:
    if (X[1] == "1" and direct == 1) or (X[1] == "2" and direct == -1):
      d.appendleft(X[2])
    else:
      d.append(X[2])
      
S = "".join(list(d))
print(S) if direct == 1 else print(S[::-1])
# Original solution
s = list(input().strip())
q = int(input().strip())
queries = []
one_count = 0
one_counts = []
for i in range(q):
    inp = input().split()
    queries.append(inp)
    if inp[0] == "1":
        one_count += 1
    one_counts.append(one_count)
one_counts = list([(one_count - x) for x in one_counts])
if one_count % 2 == 1:
    s = s[::-1]
pre = []
suf = []
for i in range(q):
    if queries[i][0] == "1":
        continue
    elif queries[i][0] == "2":
        if queries[i][1] == "1":
            if one_counts[i] % 2 == 0:
                pre.insert(0, queries[i][2])
            else:
                suf.append(queries[i][2])
        elif queries[i][1] == "2":
            if one_counts[i] % 2 == 0:
                suf.append(queries[i][2])
            else:
                pre.insert(0, queries[i][2])
print(("".join(pre + s + suf)))


# Optimized solution
s = list(input().strip())
q = int(input().strip())
queries = []
one_count = 0
one_counts = []
for i in range(q):
    inp = input().split()
    queries.append(inp)
    if inp[0] == "1":
        one_count += 1
    one_counts.append(one_count)
one_counts = list([(one_count - x) for x in one_counts])
if one_count % 2 == 1:
    s = s[::-1]
pre = []
suf = []
for i in range(q):
    if queries[i][0] == "1":
        continue
    elif queries[i][0] == "2":
        if queries[i][1] == "1":
            if one_counts[i] % 2 == 0:
                pre.append(queries[i][2])
            else:
                suf.append(queries[i][2])
        elif queries[i][1] == "2":
            if one_counts[i] % 2 == 0:
                suf.append(queries[i][2])
            else:
                pre.append(queries[i][2])
print(("".join(pre[::-1] + s + suf)))
# Original solution
import sys

def ep(*params):
    print(*params,file=sys.stderr)

l = ''
r = ''

S = input().rstrip()

Q = int(input())
mode = 0
for _ in range(Q):
    ope = list(input().split())
    if ope[0] == '1':
        mode = (mode + 1)%2
    else:
        op = (int(ope[1]) + mode)%2
        if op == 1:
            l += ope[2]
        else:
            r += ope[2]
    print(mode,l[::-1],S,r,sep=":",file=sys.stderr)    

if mode == 0:
    print(l[::-1],S,r,sep="")    
else:
    print(r[::-1],S[::-1],l,sep="")    


# Optimized solution
import sys

def ep(*params):
    print(*params,file=sys.stderr)

l = ''
r = ''

S = input().rstrip()

Q = int(input())
mode = 0
for _ in range(Q):
    ope = list(input().split())
    if ope[0] == '1':
        mode = (mode + 1)%2
    else:
        op = (int(ope[1]) + mode)%2
        if op == 1:
            l += ope[2]
        else:
            r += ope[2]
    #print(mode,l[::-1],S,r,sep=":",file=sys.stderr)    

if mode == 0:
    print(l[::-1],S,r,sep="")    
else:
    print(r[::-1],S[::-1],l,sep="")
# Original solution
S=__import__('collections').deque(input())
for _ in range(int(input())):
	T=input()
	if T<'2':S.reverse()
	else:(S.appendleft if T[2]<'2'else S.append)(T[4])
print(*S,sep='')


# Optimized solution
S,f=__import__('collections').deque(input()),0
for _ in range(int(input())):
	T=input()
	if T<'2':f=1-f
	else:(S.appendleft if (T[2]<'2')^f else S.append)(T[4])
if f:S.reverse()
print(*S,sep='')
# Original solution
s = input()
n = int(input())

rev = 0
for i in range(n):
    q = input().split()
    if q[0] == '1':
        rev = (rev + 1) % 2
    else:
        head = int(q[1]) % 2
        if head ^ rev:
            s = q[2] + s
        else:
            s += q[2]
            
print(s[::-1]) if rev else print(s)


# Optimized solution
s = input()
n = int(input())

rev = 0
sh = ''
for i in range(n):
    q = input().split()
    if q[0] == '1':
        rev = (rev + 1) % 2
    else:
        head = int(q[1]) % 2
        if head ^ rev:
            sh += q[2]
            # print('sh', sh)
        else:
            s += q[2]
            # print('s', s)
ans = sh[::-1] + s
print(ans[::-1]) if rev else print(ans)
# Original solution
import sys
from collections import deque

S=input()
Q=eval(input())
Query=[ sys.stdin.readline().split() for _ in range(Q) ]

s1=deque()
s2=deque()
judge={}
judge["front"]="s1"
judge["end"]="s2"

cnt=0
for x in Query:
    if x[0]=="1":
        n=x[0]
        cnt+=1
    elif x[0]=="2":
        n,f,c=x[0],x[1],x[2]
    if n=="1":
        judge["front"],judge["end"]=judge["end"],judge["front"]
    elif n=="2":
        if f=="1":
            if judge["front"]=="s1":
                s1.appendleft(c)
            elif judge["front"]=="s2":
                s2.append(c)
        elif f=="2":
            if judge["end"]=="s1":
                s1.appendleft(c)
            if judge["end"]=="s2":
                s2.append(c)

str1=""
for x in s1:
    str1+=x
str2=""
for x in s2:
    str2+=x

if judge["front"]=="s1" and judge["end"]=="s2":
    print(str1+S+str2)
elif judge["front"]=="s2" and judge["end"]=="s1":
    print(str2[::-1]+S[::-1]+str1[::-1])


# Optimized solution
# -*- coding: utf-8 -*-
import sys
from collections import deque
S=sys.stdin.readline().strip()
Q=int(sys.stdin.readline().strip())

cnt=0   #反転した回数
deq1=deque()
deq2=deque()

for _ in range(Q):
    t=sys.stdin.readline().split()
    if t[0]=="1": #反転
        cnt+=1      #反転回数をカウント
    elif t[0]=="2": #文字列挿入
        qtype,front_or_back,c=t[0],int(t[1]),t[2]
        if cnt%2==0:    #反転回数が偶数の場合
            if front_or_back==1:    #前に足す
                deq1.appendleft(c)
            elif front_or_back==2:  #後ろに足す
                deq2.append(c)
        else:   #反転回数が奇数の場合
            if front_or_back==1:    #前に足す
                deq2.append(c)      #反転しているので、deq2が前に来ている
            elif front_or_back==2:  #後ろに足す
                deq1.appendleft(c)  #反転しているので、deq1が前に来ている

s_deq1=""
for x in deq1:
    s_deq1+=x

s_deq2=""
for x in deq2:
    s_deq2+=x

if cnt%2==0:    #反転回数が偶数の場合
    print(s_deq1+S+s_deq2)
else:    #反転回数が奇数の場合
    print(s_deq2[::-1]+S[::-1]+s_deq1[::-1])
# Original solution
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
for i,q in enumerate(query):
  if len(q)==1:
    ans.reverse()
  else:
    _,f,c=q
    if f=='1':
      ans.appendleft(c)
    else:
      ans.append(c)
print(*ans,sep='')


# Optimized solution
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='2') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
if reverse:
  print(*reversed(ans),sep='')
else:
  print(*ans,sep='')
# Original solution
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='2') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
if reverse:
  print(*reversed(ans),sep='')
else:
  print(*ans,sep='')


# Optimized solution
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.append(c) if reverse else d.appendleft(c)
    else:
      d.appendleft(c) if reverse else d.append(c)
print(*reversed(d),sep='') if reverse else print(*d,sep='')