t=int(input())
while t>0:
    num=str(input())
    sum=0
    ok=1
    for i in range(len(num)-1):
        if abs(int(num[i])-int(num[i+1])) == 2:
            ok=0
        else:
            ok=1
            break
    for i in range(len(num)):
        sum=sum+int(num[i])
    if sum%10==0 and ok==0:
        print("YES")
    else:
        print("NO")
    t-=1
        
