f0,f1,N = map(int,input().split()) f2 = f0^f1 F = [f0,f1,f2] N = N%3 print(F[N])