#!/usr/bin/env python3 #fileencoding: utf-8 f0, f1, N = [int(i) for i in input().strip().split(" ")] print([f0,f1,f0^f1][N%3])