import Control.Monad
import Data.List

type Bar = (Int, Int, Int)

barH (h, _, _) = h

getBar :: IO Bar
getBar = do
  [h, p, q] <- liftM (map ((\x -> x - 1) . read) . words) getLine
  return $ (h, p, q)

main :: IO ()
main = loop
    where loop = do
          [n, m, a] <- liftM (map read . words) getLine
          if n == 0 then return ()
            else do
              bars <- liftM (sortBy $ \x y -> barH x `compare` barH y) $ replicateM m getBar
              let nrs = solve bars [1..n]
              print $ nrs !! (a-1)
              loop

solve [] nrs = nrs
solve ((h, p, q):bars) nrs = solve bars (swp p q nrs)

swp i j xs = map (\n -> if n == i then xs !! j else if n == j then xs !! i else xs !! n) [ 0..(length xs)-1 ]