F0, F1, N = map(int, input().split()) F2 = F0 ^ F1 N %= 3 if N == 0: print(F0) elif N == 1: print(F1) else: print(F2)