"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    let s = input[0].split(" ");
    const QN = parseInt(input[1]);
    for(let i = 2; i<2+QN; i++){
        let q = input[i].split(" ")
        if(q[0] == 1){
            const first = s[0]
            s[0] = s[s.length-1]
            s[s.length-1] = first
        } else {
            if(q[1] == 1){
                s.unshift(q[2])
            } else {
                s.push(q[2])
            }
        }
    }
    console.log(s.join(""))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  