int main(){
int t;
cin>>t;
while(t--){
long long int k , temp , sum = 0;
int d0 , d1 ;
cin>>k>>d0>>d1;
temp = (d0 + d1) % 10;
sum = d0 + d1;
if(k == 2){
if(sum%3 == 0){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
sum += temp;
long long int groups = (k - 3) / 4;
long long int remNumbers = (k - 3) % 4;
sum += (groups * 20);
for(long long int i = 0 ; i < remNumbers ; i++){
temp = (temp * 2) % 10;
sum += temp;
}
if(sum%3 == 0){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
Link to the problem
Please reply !