from collections import deque



S = input().rstrip('\r\n')

S_list = deque(S)

is_reverse = False



Q = int(eval(input()))

for _ in range(Q):

    query = input().rstrip('\r\n')

    t, f, c = '', '', ''

    if len(query) == 1:

        t = query

    else:

        t, f, c = query.split(' ')

    if t == '1':

        is_reverse = not is_reverse

    else:

        if f == '1':

            if is_reverse:

                S_list.append(c)

            else:

                S_list.appendleft(c)

        else:

            if is_reverse:

                S_list.appendleft(c)

            else:

                S_list.append(c)

if is_reverse:

    S_list.reverse()

print((''.join(S_list)))
import sys

input = sys.stdin.readline

from collections import deque

def main():

    S = input().rstrip("\r\n")

    Q = int(eval(input()))

    d = deque(S)

    reverse = False

    for _ in range(Q):

        q = input().rstrip("\r\n")

        if q == "1":

            reverse = not reverse

        else:

            _, f, c = q.split()

            if (f == "1" and not reverse) or (f == "2" and reverse):

                d.appendleft(c)

            else:

                d.append(c)

    l = list(d)

    if reverse:l.reverse()

    print(("".join(l)))

if __name__ == "__main__":

    main()
from collections import deque

S = input().rstrip("\r\n")
S_list = deque(S)
is_reverse = False
Q = int(eval(input()))
for _ in range(Q):
    query = input().rstrip("\r\n")
    t, f, c = "", "", ""
    if len(query) == 1:
        t = query
    else:
        t, f, c = query.split(" ")
    if t == "1":
        is_reverse = not is_reverse
    else:
        if f == "1":
            if is_reverse:
                S_list.append(c)
            else:
                S_list.appendleft(c)
        else:
            if is_reverse:
                S_list.appendleft(c)
            else:
                S_list.append(c)
if is_reverse:
    S_list.reverse()
print(("".join(S_list)))

import sys

input = sys.stdin.readline
from collections import deque


def main():
    S = input().rstrip("\r\n")
    Q = int(eval(input()))
    d = deque(S)
    reverse = False
    for _ in range(Q):
        q = input().rstrip("\r\n")
        if q == "1":
            reverse = not reverse
        else:
            _, f, c = q.split()
            if (f == "1" and not reverse) or (f == "2" and reverse):
                d.appendleft(c)
            else:
                d.append(c)
    l = list(d)
    if reverse:
        l.reverse()
    print(("".join(l)))


if __name__ == "__main__":
    main()

+import sys + +input = sys.stdin.readline -S = input().rstrip("\r\n") -S_list = deque(S) -is_reverse = False -Q = int(eval(input())) -for _ in range(Q): -    query = input().rstrip("\r\n") -    t, f, c = "", "", "" -    if len(query) == 1: -        t = query -    else: -        t, f, c = query.split(" ") -    if t == "1": -        is_reverse = not is_reverse -    else: -        if f == "1": -            if is_reverse: -                S_list.append(c) + +def main(): +    S = input().rstrip("\r\n") +    Q = int(eval(input())) +    d = deque(S) +    reverse = False +    for _ in range(Q): +        q = input().rstrip("\r\n") +        if q == "1": +            reverse = not reverse +        else: +            _, f, c = q.split() +            if (f == "1" and not reverse) or (f == "2" and reverse): +                d.appendleft(c) -                S_list.appendleft(c) -        else: -            if is_reverse: -                S_list.appendleft(c) -            else: -                S_list.append(c) -if is_reverse: -    S_list.reverse() -print(("".join(S_list))) +                d.append(c) +    l = list(d) +    if reverse: +        l.reverse() +    print(("".join(l))) + + +if __name__ == "__main__": +    main()