def main():

    s = eval(input())

    q = int(eval(input()))

    jun = True

    mae = ""

    ushiro = ""

    for _ in range(q):

        qu = eval(input())

        if qu == '1':

            jun = not jun

        else:

            if qu[2] == '1':

                if jun:

                    mae = qu[4] + mae

                else:

                    ushiro = ushiro + qu[4]

            else:

                if jun:

                    ushiro = ushiro + qu[4]

                else:

                    mae = qu[4] + mae

    s = mae + s + ushiro

    if not jun:

        s = s[::-1]

    print(s)

main()
from collections import deque

def main():

    s = deque(eval(input()))

    q = int(eval(input()))

    qs = [tuple(input().split()) for _ in range(q)]

    flag = 1

    for qse in qs:

        if qse[0] == '1':

            flag ^= 1

        else:

            f = int(qse[1]) - 1

            f ^= flag

            if f:

                s.appendleft(qse[2])

            else:

                s.append(qse[2])

    if flag:

        print(("".join(s)))

    else:

        ss = list(s)

        print(("".join(ss[::-1])))



if __name__ == '__main__':

    main()
def main():
    s = eval(input())
    q = int(eval(input()))
    jun = True
    mae = ""
    ushiro = ""
    for _ in range(q):
        qu = eval(input())
        if qu == "1":
            jun = not jun
        else:
            if qu[2] == "1":
                if jun:
                    mae = qu[4] + mae
                else:
                    ushiro = ushiro + qu[4]
            else:
                if jun:
                    ushiro = ushiro + qu[4]
                else:
                    mae = qu[4] + mae
    s = mae + s + ushiro
    if not jun:
        s = s[::-1]
    print(s)


main()

from collections import deque


def main():
    s = deque(eval(input()))
    q = int(eval(input()))
    qs = [tuple(input().split()) for _ in range(q)]
    flag = 1
    for qse in qs:
        if qse[0] == "1":
            flag ^= 1
        else:
            f = int(qse[1]) - 1
            f ^= flag
            if f:
                s.appendleft(qse[2])
            else:
                s.append(qse[2])
    if flag:
        print(("".join(s)))
    else:
        ss = list(s)
        print(("".join(ss[::-1])))


if __name__ == "__main__":
    main()

-def main(): -    s = eval(input()) -    q = int(eval(input())) -    jun = True -    mae = "" -    ushiro = "" -    for _ in range(q): -        qu = eval(input()) -        if qu == "1": -            jun = not jun -        else: -            if qu[2] == "1": -                if jun: -                    mae = qu[4] + mae -                else: -                    ushiro = ushiro + qu[4] -            else: -                if jun: -                    ushiro = ushiro + qu[4] -                else: -                    mae = qu[4] + mae -    s = mae + s + ushiro -    if not jun: -        s = s[::-1] -    print(s) +from collections import deque -main() +def main(): +    s = deque(eval(input())) +    q = int(eval(input())) +    qs = [tuple(input().split()) for _ in range(q)] +    flag = 1 +    for qse in qs: +        if qse[0] == "1": +            flag ^= 1 +        else: +            f = int(qse[1]) - 1 +            f ^= flag +            if f: +                s.appendleft(qse[2]) +            else: +                s.append(qse[2]) +    if flag: +        print(("".join(s))) +    else: +        ss = list(s) +        print(("".join(ss[::-1]))) + + +if __name__ == "__main__": +    main()