import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let s = readLine()!.map { String($0) }
    let q = Int(readLine()!)!

    var deque = Deque<String>()
    for c in s {
        deque.pushBack(c)
    }

    var origin = true
    for _ in 1...q {
        let query = readWords { String($0) }
        if query[0] == "1" {
            origin = !origin
        } else {
            if query[1] == "1" {
                if origin {
                    deque.pushFront(query[2])
                } else {
                    deque.pushBack(query[2])
                }
            } else {
                if origin {
                    deque.pushBack(query[2])
                } else {
                    deque.pushFront(query[2])
                }
            }
        }
    }

    var ans = [String]()
    while let c = origin ? deque.popFront() : deque.popBack() {
        ans.append(c)
    }

    print(ans.joined(separator: ""))
}

private struct Deque<T> {
    public var buffer: [T?]
    private var head: Int
    private var tail: Int

    init() {
        buffer = [T?](repeating: nil, count: 8)
        head = 0
        tail = 0
    }

    public var isEmpty: Bool {
        return tail == head
    }

    public var capacity: Int {
        return buffer.count
    }
    
    public var count: Int {
        return (head &- tail) & (capacity - 1)
    }
    
    public var isFull: Bool {
        return capacity - count == 1
    }
    
    
    private func wrapIndex(index: Int, size: Int) -> Int {
        return index & (size - 1)
    }
    
    private func wrapAdd(index: Int, append: Int) -> Int {
        return wrapIndex(index: index &+ append, size: capacity)
    }
    
    private func wrapSub(index: Int, subtrahend: Int) -> Int {
        return wrapIndex(index: index &- subtrahend, size: capacity)
    }

    mutating func growIfNecessary() {
        if isFull {
            let oldCap = capacity
            buffer.append(contentsOf: Array(repeating: nil, count: oldCap))
            handleCapacityIncrease(oldCap: oldCap)
        }
    }
    
    private mutating func handleCapacityIncrease(oldCap: Int) {
        let newCap = capacity
        
        //  T      H
        // [ooooooo.]
        //  T      H
        // [ooooooo.........]
        if tail <= head {
            // nop
        }
        //    HT
        // [oo.ooooo]
        //     T      H
        // [...ooooooo......]
        else if head < oldCap - tail {
            buffer.withUnsafeMutableBufferPointer { buf in
                let base = buf.baseAddress!
                for i in 0...head {
                    swap(&base[i], &base[i+oldCap])
                }
            }
            head += oldCap
        }
        //       HT
        // [ooooo.oo]
        //       H        T
        // [ooooo.........oo]
        else {
            let newTail = newCap - (oldCap - tail)
            buffer.withUnsafeMutableBufferPointer { buf in
                let base = buf.baseAddress!
                for i in tail..<oldCap {
                    swap(&base[i], &base[i-tail+newTail])
                }
            }
            tail = newTail
        }
    }

    public mutating func pushBack(_ element: T) {
        growIfNecessary()

        let head = self.head
        self.head = wrapAdd(index: self.head, append: 1)
        buffer[head] = element
    }

    public mutating func pushFront(_ element: T) {
        growIfNecessary()

        self.tail = wrapSub(index: self.tail, subtrahend: 1)
        let tail = self.tail
        buffer[tail] = element
    }

    mutating func popBack() -> T? {
        if isEmpty {
            return nil
        } else {
            self.head = wrapSub(index: self.head, subtrahend: 1)
            let head = self.head
            return buffer[head]
        }
    }
    
    mutating func popFront() -> T? {
        if isEmpty {
            return nil
        } else {
            let tail = self.tail
            self.tail = wrapAdd(index: self.tail, append: 1)
            return buffer[tail]
        }
    }

    func peekFront() -> T? {
        if isEmpty {
            return nil
        } else {
            return buffer[head]
        }
    }

    func peekBack() -> T? {
        if isEmpty {
            return nil
        } else {
            return buffer[tail]
        }
    }
}

main()

Measured memory_bytes: 34948