# -*- coding: utf-8 -*- F_zero, F_one, N = map(int, input().split()) F_two = F_zero ^ F_one m = N % 3 F = [F_zero, F_one, F_two] print(F[m])