import java.util.*; public class Yukicoder_64{ public static void main(String[] args){ Scanner stdIn = new Scanner(System.in); long F0 = stdIn.nextLong(); long F1 = stdIn.nextLong(); long N = stdIn.nextLong(); long count = N%(long)3; long F2 = F0^F1; if(count == 0){ System.out.println(F0); } else if(count == 1){ System.out.println(F1); } else if(count == 2){ System.out.println(F2); } } }