import java.io.*; import java.util.*; import java.math.*; class Main64 { public static void out (Object out) { System.out.println(out); } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line = br.readLine().split(" "); long f0 = Long.parseLong(line[0]); long f1 = Long.parseLong(line[1]); long n = Long.parseLong(line[2]); out(n % 3 == 0 ? f0 : n % 3 == 1 ? f1 : f0^f1); } }