# -*- coding: utf-8 -*- F = map(int, raw_input().split()) N = F[2] F[2] = F[0] ^ F[1] print F[N % 3]