def main():

    from collections import deque

    S = eval(input())

    Q = int(eval(input()))

    S = deque(S)

    flag = False

    for query in range(Q):

        a, *bc = (i for i in input().split())

        # print(a, bc)

        if a == "1":

            flag = not(flag)

        else:

            if flag:

                if bc[0] == "1":

                    S.append(bc[1])

                elif bc[0] == "2":

                    S.appendleft(bc[1])

            else:

                if bc[0] == "1":

                    S.appendleft(bc[1])

                elif bc[0] == "2":

                    S.append(bc[1])

    S = "".join(S)

    if flag:

        S = S[::-1]

    print(S)





if __name__ == '__main__':

    main()

def main():

    from collections import deque

    S = eval(input())

    Q = int(eval(input()))

    rev = 0  # 1のとき反転

    que = deque((s for s in S))

    for _ in range(Q):

        Cmd = [i for i in input().split()]

        if Cmd[0] == "1":

            rev ^= 1

        else:

            if rev == 0:

                if Cmd[1] == "1":

                    # 先頭に追加

                    que.appendleft(Cmd[2])

                else:

                    # 末尾に追加

                    que.append(Cmd[2])

            else:

                if Cmd[1] == "1":

                    # 先頭に追加

                    que.append(Cmd[2])

                else:

                    # 末尾に追加

                    que.appendleft(Cmd[2])

    ans = "".join(que)

    if rev == 1:

        ans = ans[::-1]

    print(ans)





if __name__ == '__main__':

    main()

def main():
    from collections import deque

    S = eval(input())
    Q = int(eval(input()))
    S = deque(S)
    flag = False
    for query in range(Q):
        a, *bc = (i for i in input().split())
        # print(a, bc)
        if a == "1":
            flag = not (flag)
        else:
            if flag:
                if bc[0] == "1":
                    S.append(bc[1])
                elif bc[0] == "2":
                    S.appendleft(bc[1])
            else:
                if bc[0] == "1":
                    S.appendleft(bc[1])
                elif bc[0] == "2":
                    S.append(bc[1])
    S = "".join(S)
    if flag:
        S = S[::-1]
    print(S)


if __name__ == "__main__":
    main()

def main():
    from collections import deque

    S = eval(input())
    Q = int(eval(input()))
    rev = 0  # 1のとき反転
    que = deque((s for s in S))
    for _ in range(Q):
        Cmd = [i for i in input().split()]
        if Cmd[0] == "1":
            rev ^= 1
        else:
            if rev == 0:
                if Cmd[1] == "1":
                    # 先頭に追加
                    que.appendleft(Cmd[2])
                else:
                    # 末尾に追加
                    que.append(Cmd[2])
            else:
                if Cmd[1] == "1":
                    # 先頭に追加
                    que.append(Cmd[2])
                else:
                    # 末尾に追加
                    que.appendleft(Cmd[2])
    ans = "".join(que)
    if rev == 1:
        ans = ans[::-1]
    print(ans)


if __name__ == "__main__":
    main()

-    S = deque(S) -    flag = False -    for query in range(Q): -        a, *bc = (i for i in input().split()) -        # print(a, bc) -        if a == "1": -            flag = not (flag) +    rev = 0  # 1のとき反転 +    que = deque((s for s in S)) +    for _ in range(Q): +        Cmd = [i for i in input().split()] +        if Cmd[0] == "1": +            rev ^= 1 -            if flag: -                if bc[0] == "1": -                    S.append(bc[1]) -                elif bc[0] == "2": -                    S.appendleft(bc[1]) +            if rev == 0: +                if Cmd[1] == "1": +                    # 先頭に追加 +                    que.appendleft(Cmd[2]) +                else: +                    # 末尾に追加 +                    que.append(Cmd[2]) -                if bc[0] == "1": -                    S.appendleft(bc[1]) -                elif bc[0] == "2": -                    S.append(bc[1]) -    S = "".join(S) -    if flag: -        S = S[::-1] -    print(S) +                if Cmd[1] == "1": +                    # 先頭に追加 +                    que.append(Cmd[2]) +                else: +                    # 末尾に追加 +                    que.appendleft(Cmd[2]) +    ans = "".join(que) +    if rev == 1: +        ans = ans[::-1] +    print(ans)