
function Main(arg)
{
  var S = new Array(arg.split("\n")[0]);
  var Q = arg.split("\n")[1] - 0;
  var query = arg.split("\n").slice(2);

  for (var i = 0; i < Q; i++){
    var tmp = query[i].split(" ");
    if (tmp[0] === "1") {
      S = S.reverse();
    }
    else {
      if (tmp[1] === "1") {
        S.unshift(tmp[2]);
      }
      else {
        S.push(tmp[2]);
      }
    }
  }

  console.log(S.join(""));
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));