import java.util.*; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); long[] F = new long[3]; F[0] = scan.nextLong(); F[1] = scan.nextLong(); long N = scan.nextLong(); if (F[0] < 0||F[1] < 0||N > Math.pow(10d, 18)) System.exit(1); if (N==0) { System.out.println(F[0]); System.exit(0); } else { F[2] = F[0] ^ F[1]; F[0] = F[1]; F[1] = F[2]; F[2] = F[0] ^ F[1]; System.out.println(F[((int) ((N - 1) % 3L))]); } } }