For this Question: You must have solved the problem 'Tribonacci Numbers'. Now its time for Tribonacci strings.
Given three strings T[1] = "p", T[2] = "q", T[3] = "r", 
String T[i] = T[i-1] + T[i-2] + T[i-3]
Find the character at K'th index in string T[N] (assuming 1-indexing)
Solve for Q independent queriesFirst line of input contains a single integer Q
Q lines follow, each containing two space separated numbers N and K
1 <= Q <= 10^5
1 <= N <= 60
1 <= K <= 10^16Print Q lines, each containing the character at K-th index of string T[N].
If K exceeds the length of string, print xSample Input 1:
3
6 2
6 8
6 12

Sample Output 1:
q
p
x

Explanation:
T[1] = p
T[2] = q
T[3] = r
T[4] = rqp
T[5] = rqprq
T[6] = rqprqrqpr, I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static char tribonacci(long arr[],int n,long k)
{
    if(arr[n]<k)
    return 'x';

    if(n==1)
    return 'p';

    if(n==2)
    return 'q';

    if(n==3)
    return 'r';

    if(arr[n-1]>=k)
    {
        char ans=tribonacci(arr,n-1,k);
        return ans;
    }
    else if(arr[n-1]+arr[n-2]>=k)
    {
        char ans=tribonacci(arr,n-2,k-arr[n-1]);
        return ans;
    }
    else if(arr[n-1]+arr[n-2]+arr[n-3]>=k)
    {
        char ans=tribonacci(arr,n-3,k-arr[n-1]-arr[n-2]);
        return ans;
    }
    return 'x';
}
public static void main(String args[])throws IOException
{
    InputStreamReader r=new InputStreamReader(System.in);
     BufferedReader br=new BufferedReader(r);

    int t;
    t=Integer.parseInt(br.readLine());
    while(t-->0)
    {
        String ar1[]=br.readLine().split(" ");
        int n;
        n=Integer.parseInt(ar1[0]);

        long k;
        k=Long.parseLong(ar1[1]);

        long arr[]=new long[61];

        arr[1]=1;
        arr[2]=1;
        arr[3]=1;

        for(int i=4;i<61;i++)
        {
            arr[i]=arr[i-1]+arr[i-2]+arr[i-3];
        }
        char ans=tribonacci(arr,n,k);
        System.out.println(ans);
    }
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?