open Str;;

let rec calc (r,i,n,k) =
	if i==n then r else calc((r+k) mod i,i+1,n,k);;

while true do
	let nkm = Array.of_list (List.map int_of_string (Str.split (Str.regexp " ") (read_line ()))) in
		if nkm.(0)==0 then exit(0) else (print_int((calc(0,1,nkm.(0),nkm.(1))+nkm.(2)) mod nkm.(0)+1); print_string "\n") done;;