main = interact $ unlines . map (show . attwo . map read . words) . init . lines

attwo [n,k,m] = attwo' (n-1) $ filter (/=m) $ drop (m-1) $ cycle [1..n]
 where
  attwo' 1 xs = head xs
  attwo' n' xs = attwo' (n'-1) (cycle (filter (/= x) (take n' xs')))
   where (x:xs') = drop (mod (k-1) n') xs