Can anyone help me to understand below greedy approach for solving MULTHREE.

test = int(input())
while(test):
k, d0, d1 = map(int, input().split())
temp = (d0+d1)%10
sum = d0 + d1 + temp
if not temp in (0,5):
x = (temp * 2) % 10
y = max(0,k-3)
rem = y%4
sum+= ((y//4) % 3) * 8
for i in range(rem):
sum+=x
x = (x * 2) % 10
if(sum % 3):
print(“NO”)
else:
print(“YES”)
test-=1