I don’t know which test case it is failing to show wrong answer.
Here is my code
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* 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(System.in);
int t = sc.nextInt();
while(t-->0){
long k = sc.nextLong();
long a = sc.nextInt();
long b = sc.nextInt();
ArrayList<Long> arr = new ArrayList<Long>();
arr.add(a);
arr.add(b);
if(k<2){
System.out.println("NO");
}
else{
for(int i = 2;i<Long.toString(k).length();i++){
long sum = 0;
for(int j = 0;j<i;j++){
sum = sum + arr.get(j);
}
arr.add(sum%10);
}
long res = 0;
for(int i = 0;i<arr.size();i++){
res = res + arr.get(i);
}
if(res%3==0){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
}