f0,f1,N = map(int,raw_input().split()) N %= 3 print f0 if N == 0 else f1 if N == 1 else f0^f1