from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline a,b,N = map(int,input().split()) X = [a,b,a^b] N %=3 print(X[N])