A,B,N=map(int,input().split()) F=[A,B] F.append(F[-1]^F[-2]) N%=3 print(F[N])