object Main extends App {
  import scala.io.StdIn._
  val n = readInt
  val Array(a, d) = readLine.trim.split(' ').map(_.toInt)
  val operation = Array.fill(readInt){
    val Array(x, y, z) = readLine.trim.split(' ').map(_.toInt)
    (x, y, z)
  }
  var current = readLine.trim.toInt
  for ((x, y, z) ← operation.reverse) {
    x match {
      case 0 if y == current || z == current ⇒
        current = if (y == current) z else y
      case 1 if y == current ⇒ current = z
      case _ ⇒
    }
  }
  println(a + current * d - d)
}

