import java.util.*; import static java.lang.System.*; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { long F0 = sc.nextLong(); long F1 = sc.nextLong(); long n = sc.nextLong(); long F2 = F0^F1; long ans; if(n%3==0)ans=F0; else if (n%3==1)ans=F1; else ans=F2; out.println(ans); } }