"use strict";
function main(input) {
  let s = input[0];
  let q = parseInt(input[1]);

  for(let i=0;i<q;i++){
    let kari = input[i+2].trim().split(" ");
    let query = parseInt(kari[0]);
    if(query===1){
      s = s.split("").reverse().join("");
    }else{
      let f = parseInt(kari[1]);
      let c = kari[2];
      if(f === 1){
        s = c + s;
      }else{
        s = s + c;
      }
    }
  }

  console.log(s);
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));