console.log((args=>{
  const [S,q,...tmp] = args.trim().split`\n`;
  const Q = q|0;
  const s = Array(Q).fill('').concat( S.split``, Array(Q).fill('') );
  let ol = Q-1, or = S.length+Q, r = false;
  for ( let i = 0; i < Q; i++ ) {
    const [cmd,f,c] = tmp[i].split` `;
    if ( cmd === '1' ) r = !r;
    else if (r^(f-1)) s[or++] = c;
    else s[ol--] = c;
  }
  if (r) s.reverse();
  return s.join``;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
