telefone sem validar
# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
for _ in range(int(input())):
if re.match(r'[789]\d{9}$',input()):
print('YES')
else:
print('NO')
sree_007