Solution : CodeChef: Practical coding for everyone
from sys import stdin,stdout
T=int(stdin.readline())
for i in range(T):
K,d0,d1=stdin.readline().split()
K=int(K)
d0=int(d0)
d1=int(d1)
sum1=int(d0+d1+int((d0+d1)%10))
start=int(sum1%10)
if start==8:
list=[8,6,2,4]
elif start==6:
list=[6,2,4,8]
elif start==2:
list=[2,4,8,6]
else:
list=[4,8,6,2]
K=K-3
quotient=int(K/4)*20
sum1=sum1+quotient
rem=int(K%4)
sum1=sum1+sum(list[:rem])
if int(sum1%3)==0:
print("YES")
else:
print("NO")