import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] inputs = reader.readLine().split(" "); long f0 = Long.parseLong(inputs[0]); long f1 = Long.parseLong(inputs[1]); long N = Long.parseLong(inputs[2]); long[] fs = new long[3]; fs[0] = f0; fs[1] = f1; fs[2] = f1 ^ f0; System.out.println(fs[(int)(N % 3)]); } }