*F, N = map(int, input().split()) print(F[0]^F[1] if N%3==2 else F[N%3])