#coding:utf-8 F0,F1,N=map(int,raw_input().split()) F2=F0^F1 ans=N%3 if ans==0: print F0 elif ans==1: print F1 else: print F2