main = interact $ unlines . map (show . attwo . map read . words) . init . lines
??
attwo [n,k,m] = attwo' $ take (n-1) $ tail $ dropWhile (/=m) (cycle [1..n])
??where
????attwo' [x] = x
????attwo' xs = attwo' (filter (/= x) (take (length xs) xs'))
??????where (x:xs') = (drop (k-1) (cycle xs))