Help me in solving FIBXOR01 problem

My issue

how to solve this

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.util.Scanner;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
	public static void main (String[] args) throws java.lang.Exception
		// your code goes here
		Scanner sc = new Scanner(;
		int k = sc.nextInt();
		for( int i=0; i<k;i++){
		    int a=sc.nextInt();
		    int b=sc.nextInt();
		    int n=sc.nextInt();
		    System.out.println(fib(a, b, n)+"\n");
	public static int fib(int a, int b, int n ){
	    if (n==1){
	       return b;
	    else if (n==0){
	        return a;
	    return fib(a, b ,n-1) ^ fib(a, b ,n-2);

Problem Link: FIBXOR01 Problem - CodeChef

n is upto 10^9.
this will give u tle;
if u find for smaller values u will observe that the values will repeat.
only three values a,b,a^b.