# https://www.hackerrank.com/challenges/validating-the-phone-number/problem

#FCK REGEX
if __name__ == '__main__':

    N = int(input())
    firstNumbers = "978"

    for _ in range(N):

        usr_input = input()
        isContainsAlpha = False

        for character in usr_input:
                if character.isalpha():
                    isContainsAlpha = True


        if usr_input[0] in firstNumbers and len(usr_input) == 10 and not(isContainsAlpha):
            print("YES")
        else:
            print("NO")

# https://www.hackerrank.com/challenges/validating-the-phone-number/problem

#FCK REGEX
if __name__ == '__main__':

    N = int(input())
    firstNumbers = "978"

    for _ in range(N):

        usr_input = input()
        isContainsAlpha = False

        for character in usr_input:
                if character.isalpha():
                    isContainsAlpha = True


        if usr_input[0] in firstNumbers and len(usr_input) == 10 and not(isContainsAlpha):
            print("YES")
        else:
            print("NO")

# https://www.hackerrank.com/challenges/validating-the-phone-number/problem #FCK REGEX