import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; public class Main { public static void main(String[] args) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); try { String[] box = buff.readLine().split(" "); BigInteger[] f = new BigInteger[2]; f[0] = new BigInteger(box[0]); f[1] = new BigInteger(box[1]); BigInteger n = new BigInteger(box[2]); if ((n.remainder(new BigInteger("3")).intValue()) < 2) { System.out.println(f[(n.remainder(new BigInteger("3")).intValue())]); } else { BigInteger w = f[0].xor(f[1]); System.out.println(w); } } catch (NumberFormatException e) { e.getStackTrace(); } catch (IOException e) { e.getStackTrace(); } catch (Exception e) { e.getStackTrace(); } } }