/* package codechef; // don’t place package name! */
here is the quuestion link
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
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
for(int i=0;i<t;i++){
String []arr=sc.nextLine().split(" ");
long k = Long.parseLong(arr[0]);
int sum= Integer.parseInt(arr[1])+Integer.parseInt(arr[2]);
int output;
if(k==2)
output=sum;
else if(k==3)
output=sum+sum%10;
else
{
int a= (2*sum)%10;
int b= (4*sum)%10;
int c= (8*sum)%10;
int d= (6*sum)%10;
output= sum+sum%10+(int)((k-3)/4)*(a+b+c+d);
k=k-3;
k=k%4;
if(k==1)
output=output+a;
if(k==2)
output=output+a+b;
if(k==3)
output=output+a+b+c;
}
if(output%3==0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
I am getting wrong answer but don;t know why??